kontena / pharos-cluster

Pharos - The Kubernetes Distribution
https://k8spharos.dev/
Apache License 2.0
311 stars 43 forks source link

undefined method `[]' for nil:NilClass (NoMethodError) #501

Closed antonyveyre closed 6 years ago

antonyveyre commented 6 years ago

Launching pharos from Mac os to ubuntu on vmware give this issue.

Traceback :

Traceback (most recent call last):
    6: from /pharos-cluster/lib/pharos/phase_manager.rb:26:in `block (2 levels) in run_parallel'
    5: from /pharos-cluster/lib/pharos/phase_manager.rb:70:in `block in apply'
    4: from /pharos-cluster/lib/pharos/phases/gather_facts.rb:14:in `call'
    3: from /pharos-cluster/lib/pharos/phases/gather_facts.rb:25:in `gather_host_facts'
    2: from /pharos-cluster/lib/pharos/phases/gather_facts.rb:60:in `cpu_arch'
    1: from /pharos-cluster/lib/pharos/phases/gather_facts.rb:60:in `each'
/pharos-cluster/lib/pharos/phases/gather_facts.rb:62:in `block in cpu_arch': undefined method `[]' for nil:NilClass (NoMethodError)

Found solution:

diff --git a/lib/pharos/phases/gather_facts.rb b/lib/pharos/phases/gather_facts.rb
index ccb7e67..8162a0e 100644
--- a/lib/pharos/phases/gather_facts.rb
+++ b/lib/pharos/phases/gather_facts.rb
@@ -56,13 +56,9 @@ module Pharos

       # @return [Pharos::Configuration::CpuArch]
       def cpu_arch
-        cpu = {}
-        @ssh.exec!('lscpu').split("\n").each do |line|
-          match = line.match(/^(.+):\s+(.+)$/)
-          cpu[match[1]] = match[2]
-        end
+        arch = @ssh.exec!('uname -m')
         Pharos::Configuration::CpuArch.new(
-          id: cpu['Architecture']
+          id: arch.tap{|x| x.strip!}
         )
       end
SpComb commented 6 years ago

Can you show what lscpu on the Ubuntu host outputs?

Agreed that the loop should skip mismatching lines, but uname -m would be better anyways.

antonyveyre commented 6 years ago

ubuntu@master0:~$ uname -m x86_64

ubuntu@master0:~$ lscpu Architecture : x86_64 Mode(s) opératoire(s) des processeurs :32-bit, 64-bit Boutisme : Little Endian Processeur(s) : 2 Liste de processeur(s) en ligne :0,1 Thread(s) par cœur : 1 Cœur(s) par socket : 1 Socket(s) : 2 Nœud(s) NUMA : 1 Identifiant constructeur :AuthenticAMD Famille de processeur :23 Modèle : 1 Nom de modèle : AMD Ryzen 7 1800X Eight-Core Processor Révision : 1 Vitesse du processeur en MHz :3599.999 BogoMIPS : 7199.99 Constructeur d'hyperviseur :VMware Type de virtualisation :complet Cache L1d : 32K Cache L1i : 64K Cache L2 : 512K Cache L3 : 16384K Nœud NUMA 0 de processeur(s) :0,1 Drapaux : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc extd_apicid aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw cpb ssbd vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt xsaveopt xsavec clzero arat

Respectueusement, Antony VEYRE

Le 7 août 2018 à 12:38, Tero Marttila notifications@github.com a écrit :

Can you show what lscpu on the Ubuntu host outputs? Agreed that the loop should skip mismatching lines, but uname -m would be better anyways. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

SpComb commented 6 years ago
Architecture : x86_64

Looks like there's extra whitespace before the colon that we're not matching?

Mode(s) opératoire(s) des processeurs :32-bit, 64-bit

Uuh... I think we need some LC_ALL=C.UTF-8 to negate any locales getting sent over SSH... we may only be testing with en_* locales?

antonyveyre commented 6 years ago

with LC_ALL=en_us.UTF-8 it's ok :

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    1
Socket(s):             2
NUMA node(s):          1
Vendor ID:             AuthenticAMD
CPU family:            23
Model:                 1
Model name:            AMD Ryzen 7 1800X Eight-Core Processor
Stepping:              1
CPU MHz:               3599.999
BogoMIPS:              7199.99
Hypervisor vendor:     VMware
Virtualization type:   full
L1d cache:             32K
L1i cache:             64K
L2 cache:              512K
L3 cache:              16384K
NUMA node0 CPU(s):     0,1
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl tsc_reliable nonstop_tsc extd_apicid aperfmperf eagerfpu pni pclmulqdq ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw cpb ssbd vmmcall fsgsbase bmi1 avx2 smep bmi2 rdseed adx smap clflushopt xsaveopt xsavec clzero arat
bash: warning: setlocale: LC_ALL: cannot change locale (en_us.UTF-8)
antonyveyre commented 6 years ago

do you want a pull-request for change lscpu to uname -m ?

SpComb commented 6 years ago

do you want a pull-request for change lscpu to uname -m ?

In this case the only thing being read from lscpu is the Architecture, so sure... using uname -m instead would be an improvement.

Although avoid using strip! to mutate strings... just use arch.strip, the .tap { ... } is unnecessary.

antonyveyre commented 6 years ago

will fix that and make a pull-request if it's ok.

jakolehm commented 6 years ago

Fixed in #505