kanrisuru 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.github/CONTRIBUTING.md +9 -9
  3. data/.github/ISSUE_TEMPLATE/bug_report.md +7 -8
  4. data/.gitignore +3 -1
  5. data/CHANGELOG.md +147 -125
  6. data/CODE_OF_CONDUCT.md +10 -10
  7. data/README.md +2 -0
  8. data/kanrisuru.gemspec +2 -1
  9. data/lib/kanrisuru/core/archive.rb +6 -5
  10. data/lib/kanrisuru/core/disk.rb +0 -3
  11. data/lib/kanrisuru/core/find.rb +4 -5
  12. data/lib/kanrisuru/core/socket.rb +2 -1
  13. data/lib/kanrisuru/remote/cpu.rb +6 -2
  14. data/lib/kanrisuru/remote/env.rb +8 -0
  15. data/lib/kanrisuru/remote/fstab.rb +4 -4
  16. data/lib/kanrisuru/util.rb +1 -1
  17. data/lib/kanrisuru/version.rb +1 -1
  18. data/spec/functional/core/apt_spec.rb +22 -30
  19. data/spec/functional/core/archive_spec.rb +169 -0
  20. data/spec/functional/core/find_spec.rb +94 -113
  21. data/spec/functional/core/socket_spec.rb +23 -28
  22. data/spec/functional/core/stream_spec.rb +12 -12
  23. data/spec/functional/core/transfer_spec.rb +108 -131
  24. data/spec/functional/core/yum_spec.rb +58 -83
  25. data/spec/functional/remote/cluster_spec.rb +12 -3
  26. data/spec/functional/remote/cpu_spec.rb +104 -0
  27. data/spec/functional/remote/env_spec.rb +48 -0
  28. data/spec/helper/stub_network.rb +52 -9
  29. data/spec/integration/core/file_spec.rb +0 -1
  30. data/spec/integration/core/find_spec.rb +1 -0
  31. data/spec/integration/core/system_spec.rb +0 -1
  32. data/spec/integration/core/zypper_spec.rb +3 -3
  33. data/spec/{functional → integration}/os_package_spec.rb +0 -0
  34. data/spec/spec_helper.rb +3 -0
  35. data/spec/unit/command_spec.rb +31 -0
  36. data/spec/unit/core/apt_spec.rb +20 -0
  37. data/spec/unit/core/archive_spec.rb +20 -0
  38. data/spec/unit/core/disk_spec.rb +23 -0
  39. data/spec/unit/core/dmi_spec.rb +20 -0
  40. data/spec/unit/core/file_spec.rb +35 -0
  41. data/spec/unit/core/find_spec.rb +21 -1
  42. data/spec/unit/core/group_spec.rb +24 -0
  43. data/spec/unit/core/ip_spec.rb +20 -0
  44. data/spec/unit/core/path_spec.rb +25 -0
  45. data/spec/unit/core/socket_spec.rb +20 -0
  46. data/spec/unit/core/stat_spec.rb +27 -0
  47. data/spec/unit/core/system_spec.rb +35 -0
  48. data/spec/unit/core/transfer_spec.rb +22 -0
  49. data/spec/unit/core/user_spec.rb +25 -0
  50. data/spec/unit/core/yum_spec.rb +20 -0
  51. data/spec/unit/core/zypper_spec.rb +20 -0
  52. data/spec/unit/mode_spec.rb +33 -2
  53. data/spec/unit/remote/cluster_spec.rb +36 -0
  54. data/spec/unit/remote/cpu_spec.rb +49 -0
  55. data/spec/unit/remote/env_spec.rb +17 -0
  56. data/spec/unit/{fstab_spec.rb → remote/fstab_spec.rb} +0 -0
  57. data/spec/unit/util_spec.rb +13 -0
  58. metadata +27 -5
@@ -14,7 +14,7 @@ RSpec.describe Kanrisuru::Core::Stat do
14
14
  let(:host) do
15
15
  Kanrisuru::Remote::Host.new(
16
16
  host: 'localhost',
17
- username: 'ubuntu',
17
+ username: 'ubuntu',
18
18
  keys: ['id_rsa']
19
19
  )
20
20
  end
@@ -23,165 +23,142 @@ RSpec.describe Kanrisuru::Core::Stat do
23
23
  url = 'https://rubygems.org'
24
24
 
25
25
  expect_command(host.wget(url),
26
- "wget #{url}"
27
- )
26
+ "wget #{url}")
28
27
 
29
28
  ## Output options
30
- expect_command(host.wget(url,
31
- quiet: true, verbose: false, log_file: '/var/log/wget.log'),
32
- "wget --quiet --no-verbose --output-file /var/log/wget.log #{url}"
33
- )
29
+ expect_command(host.wget(url,
30
+ quiet: true, verbose: false, log_file: '/var/log/wget.log'),
31
+ "wget --quiet --no-verbose --output-file /var/log/wget.log #{url}")
34
32
 
35
- expect_command(host.wget(url,
36
- verbose: true, append_log_file: '/var/log/wget.log'),
37
- "wget --verbose --append-output /var/log/wget.log #{url}"
38
- )
33
+ expect_command(host.wget(url,
34
+ verbose: true, append_log_file: '/var/log/wget.log'),
35
+ "wget --verbose --append-output /var/log/wget.log #{url}")
39
36
 
40
37
  ## Download options
41
38
  expect_command(host.wget(url,
42
- bind_address: '0.0.0.0',
43
- retries: 3,
44
- output_document: '/home/ubuntu/index.html',
45
- no_clobber: true,
46
- timeout: 30,
47
- dns_timeout: 60,
48
- connect_timeout: 60,
49
- read_timeout: 15,
50
- limit_rate: '120k',
51
- wait: 5,
52
- waitretry: 15,
53
- random_wait: true,
54
- no_proxy: true,
55
- no_dns_cache: true
56
- ),
57
- "wget --bind-address 0.0.0.0 --tries 3 --output-document /home/ubuntu/index.html --no-clobber --timeout 30 --dns-timeout 60 --connect-timeout 60 --read-timeout 15 --limit-rate 120k --wait 5 --waitretry 15 --random-wait --no-proxy --no-dns-cache https://rubygems.org"
58
- )
39
+ bind_address: '0.0.0.0',
40
+ retries: 3,
41
+ output_document: '/home/ubuntu/index.html',
42
+ no_clobber: true,
43
+ timeout: 30,
44
+ dns_timeout: 60,
45
+ connect_timeout: 60,
46
+ read_timeout: 15,
47
+ limit_rate: '120k',
48
+ wait: 5,
49
+ waitretry: 15,
50
+ random_wait: true,
51
+ no_proxy: true,
52
+ no_dns_cache: true),
53
+ 'wget --bind-address 0.0.0.0 --tries 3 --output-document /home/ubuntu/index.html --no-clobber --timeout 30 --dns-timeout 60 --connect-timeout 60 --read-timeout 15 --limit-rate 120k --wait 5 --waitretry 15 --random-wait --no-proxy --no-dns-cache https://rubygems.org')
59
54
 
60
55
  ## Other Options
61
56
  expect_command(host.wget(url,
62
- quota: 'inf',
63
- family: 'inet',
64
- restrict_file_names: ['unix', 'ascii', 'lowercase', 'uppercase'],
65
- retry_connrefused: true,
66
- user: 'admin',
67
- password: 'admin',
68
- no_iri: true,
69
- ),
70
- "wget --quota inf --restrict-file-names unix,ascii,lowercase,uppercase --inet4-only --retry-connrefused --user admin --password admin --no-iri #{url}"
71
- )
57
+ quota: 'inf',
58
+ family: 'inet',
59
+ restrict_file_names: %w[unix ascii lowercase uppercase],
60
+ retry_connrefused: true,
61
+ user: 'admin',
62
+ password: 'admin',
63
+ no_iri: true),
64
+ "wget --quota inf --restrict-file-names unix,ascii,lowercase,uppercase --inet4-only --retry-connrefused --user admin --password admin --no-iri #{url}")
72
65
 
73
66
  ## Directories
74
67
  expect_command(host.wget(url,
75
- no_directories: true,
76
- no_host_directories: true,
77
- cut_dirs: 3,
78
- directory_prefix: '~/downloads/'
79
- ),
80
- "wget --no-directories --no-host-directories --cut-dirs 3 --directory-prefix ~/downloads/ #{url}"
81
- )
68
+ no_directories: true,
69
+ no_host_directories: true,
70
+ cut_dirs: 3,
71
+ directory_prefix: '~/downloads/'),
72
+ "wget --no-directories --no-host-directories --cut-dirs 3 --directory-prefix ~/downloads/ #{url}")
82
73
 
83
74
  ## HTTP
84
75
  expect_command(host.wget(url,
85
- default_page: 'index.html',
86
- adjust_extension: true,
87
- http_user: 'admin',
88
- http_password: 'admin',
89
- load_cookies: '~/cookies.txt',
90
- save_cookies: '~/cookies.txt',
91
- no_cache: true,
92
- keep_session_cookies: true,
93
- ignore_length: true,
94
- headers: {
95
- 'Accept-Language' => 'hr',
96
- 'Authorization' => 'Bearer 1234'
97
- },
98
- max_redirect: 5,
99
- proxy_user: 'admin',
100
- proxy_password: '12345678'
101
- ),
102
- "wget --default-page index.html --adjust-extension --http-user admin --http-password admin --load-cookies ~/cookies.txt --save-cookies ~/cookies.txt --no-cache --keep-session-cookies --ignore-length --max-redirect 5 --proxy-user admin --proxy-password 12345678 --header 'Accept-Language: hr' --header 'Authorization: Bearer 1234' #{url}"
103
- )
76
+ default_page: 'index.html',
77
+ adjust_extension: true,
78
+ http_user: 'admin',
79
+ http_password: 'admin',
80
+ load_cookies: '~/cookies.txt',
81
+ save_cookies: '~/cookies.txt',
82
+ no_cache: true,
83
+ keep_session_cookies: true,
84
+ ignore_length: true,
85
+ headers: {
86
+ 'Accept-Language' => 'hr',
87
+ 'Authorization' => 'Bearer 1234'
88
+ },
89
+ max_redirect: 5,
90
+ proxy_user: 'admin',
91
+ proxy_password: '12345678'),
92
+ "wget --default-page index.html --adjust-extension --http-user admin --http-password admin --load-cookies ~/cookies.txt --save-cookies ~/cookies.txt --no-cache --keep-session-cookies --ignore-length --max-redirect 5 --proxy-user admin --proxy-password 12345678 --header 'Accept-Language: hr' --header 'Authorization: Bearer 1234' #{url}")
104
93
 
105
94
  expect_command(host.wget(url,
106
- post_data: {
107
- url: "https://example.com?param=123"
108
- },
109
- content_disposition: true,
110
- secure_protocol: 'SSLv3',
111
- no_check_certificate: true,
112
- ),
113
- "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}"
114
- )
115
-
116
- expect {
95
+ post_data: {
96
+ url: 'https://example.com?param=123'
97
+ },
98
+ content_disposition: true,
99
+ secure_protocol: 'SSLv3',
100
+ no_check_certificate: true),
101
+ "wget --post-data url=https%3A%2F%2Fexample.com%3Fparam%3D123 --content-disposition --secure-protocol SSLv3 --no-check-certificate #{url}")
102
+
103
+ expect do
117
104
  host.wget(url, secure_protocol: 'SSL')
118
- }.to raise_error(ArgumentError)
105
+ end.to raise_error(ArgumentError)
119
106
 
120
107
  expect_command(host.wget(url,
121
- certificate: '~/cert.pem',
122
- certificate_type: 'PEM',
123
- private_key: '~/key.pem',
124
- private_key_type: 'PEM',
125
- ca_certificate: '~/ca.pem',
126
- random_file: '~/random'
127
- ),
128
- "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
129
- )
108
+ certificate: '~/cert.pem',
109
+ certificate_type: 'PEM',
110
+ private_key: '~/key.pem',
111
+ private_key_type: 'PEM',
112
+ ca_certificate: '~/ca.pem',
113
+ random_file: '~/random'),
114
+ "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}")
130
115
 
131
116
  expect_command(host.wget(url,
132
- certificate: '~/cert.pem',
133
- certificate_type: 'PEM',
134
- private_key: '~/key.pem',
135
- private_key_type: 'PEM',
136
- ca_certificate: '~/ca.pem',
137
- random_file: '~/random'
138
- ),
139
- "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}"
140
- )
117
+ certificate: '~/cert.pem',
118
+ certificate_type: 'PEM',
119
+ private_key: '~/key.pem',
120
+ private_key_type: 'PEM',
121
+ ca_certificate: '~/ca.pem',
122
+ random_file: '~/random'),
123
+ "wget --certificate ~/cert.pem --certificate-type PEM --private-key ~/key.pem --private-key-type PEM --ca-certificate ~/ca.pem --random-file ~/random #{url}")
141
124
 
142
125
  ## FTP
143
- expect_command(host.wget(url,
144
- ftp_user: 'admin',
145
- ftp_password: '12345678',
146
- no_remove_listing: true,
147
- no_glob: true,
148
- no_passive_ftp: true,
149
- retr_symlinks: true
150
- ),
151
- "wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}"
152
- )
126
+ expect_command(host.wget(url,
127
+ ftp_user: 'admin',
128
+ ftp_password: '12345678',
129
+ no_remove_listing: true,
130
+ no_glob: true,
131
+ no_passive_ftp: true,
132
+ retr_symlinks: true),
133
+ "wget --ftp-user admin --ftp-password 12345678 --no-remove-listing --no-glob --no-passive-ftp --retr-symlinks #{url}")
153
134
 
154
135
  ## Recursive Retrieval
155
136
  expect_command(host.wget(url,
156
- recursive: true,
157
- depth: 10,
158
- delete_after: true,
159
- convert_links: true,
160
- backup_converted: true,
161
- mirror: true,
162
- page_requisites: true,
163
- strict_comments: true
164
- ),
165
- "wget --recursive --level 10 --delete-after --convert-links --backup-converted --mirror --page-requisites --strict-comments #{url}"
166
- )
137
+ recursive: true,
138
+ depth: 10,
139
+ delete_after: true,
140
+ convert_links: true,
141
+ backup_converted: true,
142
+ mirror: true,
143
+ page_requisites: true,
144
+ strict_comments: true),
145
+ "wget --recursive --level 10 --delete-after --convert-links --backup-converted --mirror --page-requisites --strict-comments #{url}")
167
146
 
168
147
  ## Recursive Accept/Reject
169
148
  expect_command(host.wget(url,
170
- accept_list: ['.txt', '.html'],
171
- reject_list: ['.csv'],
172
- domain_list: ['example.com'],
173
- exclude_domain_list: ['hackernews.com'],
174
- follow_tags: ['a', 'div', 'span'],
175
- ignore_tags: ['area', 'link'],
176
- include_directories: ['/gems'],
177
- exclude_directories: ['/releases'],
178
- follow_ftp: true,
179
- ignore_case: true,
180
- span_hosts: true,
181
- relative: true,
182
- no_parent: true
183
- ),
184
- "wget --accept .txt,.html --reject .csv --domains example.com --exclude-domains hackernews.com --follow-tags a,div,span --ignore-tags area,link --include-directories /gems --exclude-directories /releases --follow-ftp --ignore-case --span-hosts --relative --no-parent #{url}"
185
- )
149
+ accept_list: ['.txt', '.html'],
150
+ reject_list: ['.csv'],
151
+ domain_list: ['example.com'],
152
+ exclude_domain_list: ['hackernews.com'],
153
+ follow_tags: %w[a div span],
154
+ ignore_tags: %w[area link],
155
+ include_directories: ['/gems'],
156
+ exclude_directories: ['/releases'],
157
+ follow_ftp: true,
158
+ ignore_case: true,
159
+ span_hosts: true,
160
+ relative: true,
161
+ no_parent: true),
162
+ "wget --accept .txt,.html --reject .csv --domains example.com --exclude-domains hackernews.com --follow-tags a,div,span --ignore-tags area,link --include-directories /gems --exclude-directories /releases --follow-ftp --ignore-case --span-hosts --relative --no-parent #{url}")
186
163
  end
187
164
  end
@@ -20,117 +20,94 @@ RSpec.describe Kanrisuru::Core::Yum do
20
20
  end
21
21
 
22
22
  it 'prepares yum install command' do
23
- expect_command(host.yum('install', packages: 'nginx'),
24
- 'yum install -y nginx'
25
- )
23
+ expect_command(host.yum('install', packages: 'nginx'),
24
+ 'yum install -y nginx')
26
25
 
27
- expect_command(host.yum('install', packages: ['nginx', 'apache2']),
28
- 'yum install -y nginx apache2'
29
- )
26
+ expect_command(host.yum('install', packages: %w[nginx apache2]),
27
+ 'yum install -y nginx apache2')
30
28
  end
31
29
 
32
30
  it 'prepares yum localinstall command' do
33
- expect_command(host.yum('localinstall', repos: 'foo.rpm'),
34
- 'yum localinstall -y foo.rpm'
35
- )
31
+ expect_command(host.yum('localinstall', repos: 'foo.rpm'),
32
+ 'yum localinstall -y foo.rpm')
36
33
 
37
- expect_command(host.yum('localinstall',
38
- repos: ['foo.rpm', 'bar.rpm', 'baz.rpm'],
39
- disable_repo: '*'
40
- ),
41
- 'yum localinstall --disablerepo=* -y foo.rpm bar.rpm baz.rpm'
42
- )
34
+ expect_command(host.yum('localinstall',
35
+ repos: ['foo.rpm', 'bar.rpm', 'baz.rpm'],
36
+ disable_repo: '*'),
37
+ 'yum localinstall --disablerepo=* -y foo.rpm bar.rpm baz.rpm')
43
38
  end
44
39
 
45
40
  it 'prepares yum list command' do
46
- expect_command(host.yum('list'),
47
- "yum list | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
48
- )
41
+ expect_command(host.yum('list'),
42
+ "yum list | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
49
43
 
50
44
  expect_command(host.yum('list', all: true, query: 'ruby*'),
51
- "yum list all ruby* | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
52
- )
53
-
54
- expect_command(host.yum('list',
55
- available: true,
56
- updates: true,
57
- installed: true,
58
- extras: true,
59
- obsoletes: true,
60
- disable_repo: '*'
61
- ),
62
- "yum list --disablerepo=* available updates installed extras obsoletes | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
63
- )
45
+ "yum list all ruby* | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
46
+
47
+ expect_command(host.yum('list',
48
+ available: true,
49
+ updates: true,
50
+ installed: true,
51
+ extras: true,
52
+ obsoletes: true,
53
+ disable_repo: '*'),
54
+ "yum list --disablerepo=* available updates installed extras obsoletes | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
64
55
  end
65
56
 
66
57
  it 'prepares yum search command' do
67
- expect_command(host.yum('search',
68
- packages: 'redis'
69
- ),
70
- "yum search redis | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
71
- )
58
+ expect_command(host.yum('search',
59
+ packages: 'redis'),
60
+ "yum search redis | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
72
61
 
73
62
  expect_command(host.yum('search',
74
- packages: ['package1', 'package2', 'package3'],
75
- all: true
76
- ),
77
- "yum search all package1 package2 package3 | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
78
- )
63
+ packages: %w[package1 package2 package3],
64
+ all: true),
65
+ "yum search all package1 package2 package3 | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'")
79
66
  end
80
67
 
81
68
  it 'prepares yum info command' do
82
- expect_command(host.yum('info',
83
- packages: 'redis'
84
- ),
85
- "yum info --quiet redis"
86
- )
87
-
88
- expect_command(host.yum('info',
89
- packages: ['package1', 'package2', 'package3'],
90
- installed: true
91
- ),
92
- "yum info --quiet installed package1 package2 package3"
93
- )
69
+ expect_command(host.yum('info',
70
+ packages: 'redis'),
71
+ 'yum info --quiet redis')
72
+
73
+ expect_command(host.yum('info',
74
+ packages: %w[package1 package2 package3],
75
+ installed: true),
76
+ 'yum info --quiet installed package1 package2 package3')
94
77
  end
95
78
 
96
79
  it 'prepares yum repolist command' do
97
80
  expect_command(host.yum('repolist'),
98
- "yum repolist --verbose"
99
- )
81
+ 'yum repolist --verbose')
100
82
 
101
83
  expect_command(host.yum('repolist', repos: 'repo1'),
102
- "yum repolist --verbose repo1"
103
- )
84
+ 'yum repolist --verbose repo1')
104
85
 
105
- expect_command(host.yum('repolist', repos: ['repo1', 'repo2', 'repo3']),
106
- "yum repolist --verbose repo1 repo2 repo3"
107
- )
86
+ expect_command(host.yum('repolist', repos: %w[repo1 repo2 repo3]),
87
+ 'yum repolist --verbose repo1 repo2 repo3')
108
88
  end
109
89
 
110
90
  it 'prepares yum clean command' do
111
91
  expect_command(host.yum('clean'), 'yum clean')
112
92
  expect_command(host.yum('clean', all: true), 'yum clean all')
113
- expect_command(host.yum('clean',
114
- dbcache: true,
115
- expire_cache: true,
116
- metadata: true,
117
- packages: true,
118
- headers: true,
119
- rpmdb: true
120
- ),
121
- "yum clean dbcache expire-cache metadata packages headers rpmdb"
122
- )
123
- end
93
+ expect_command(host.yum('clean',
94
+ dbcache: true,
95
+ expire_cache: true,
96
+ metadata: true,
97
+ packages: true,
98
+ headers: true,
99
+ rpmdb: true),
100
+ 'yum clean dbcache expire-cache metadata packages headers rpmdb')
101
+ end
124
102
 
125
103
  it 'prepares yum remove command' do
126
- expect_command(host.yum('remove', packages: 'gcc'), 'yum remove -y gcc')
127
- expect_command(host.yum('remove', packages: ['p1', 'p2', 'p3']),
128
- 'yum remove -y p1 p2 p3'
129
- )
104
+ expect_command(host.yum('remove', packages: 'gcc'), 'yum remove -y gcc')
105
+ expect_command(host.yum('remove', packages: %w[p1 p2 p3]),
106
+ 'yum remove -y p1 p2 p3')
130
107
 
131
- expect {
108
+ expect do
132
109
  host.yum('remove', packages: 'yum')
133
- }.to raise_error(ArgumentError)
110
+ end.to raise_error(ArgumentError)
134
111
  end
135
112
 
136
113
  it 'prepares yum autoremove command' do
@@ -139,13 +116,12 @@ RSpec.describe Kanrisuru::Core::Yum do
139
116
 
140
117
  it 'prepares yum erase command' do
141
118
  expect_command(host.yum('erase', packages: 'gcc'), 'yum erase -y gcc')
142
- expect_command(host.yum('erase', packages: ['p1', 'p2', 'p3']),
143
- 'yum erase -y p1 p2 p3'
144
- )
119
+ expect_command(host.yum('erase', packages: %w[p1 p2 p3]),
120
+ 'yum erase -y p1 p2 p3')
145
121
 
146
- expect {
122
+ expect do
147
123
  host.yum('erase', packages: 'yum')
148
- }.to raise_error(ArgumentError)
124
+ end.to raise_error(ArgumentError)
149
125
  end
150
126
 
151
127
  it 'prepares yum update command' do
@@ -155,5 +131,4 @@ RSpec.describe Kanrisuru::Core::Yum do
155
131
  it 'prepares yum upgrade command' do
156
132
  expect_command(host.yum('upgrade'), 'yum upgrade -y')
157
133
  end
158
-
159
134
  end
@@ -28,7 +28,7 @@ RSpec.describe Kanrisuru::Remote::Cluster do
28
28
  end
29
29
 
30
30
  it 'adds host to a cluster' do
31
- cluster = Kanrisuru::Remote::Cluster.new(host1)
31
+ cluster = described_class.new(host1)
32
32
  expect(cluster.hosts.length).to eq(1)
33
33
  expect(cluster.count).to eq(1)
34
34
  expect(cluster[host1.host]).to eq(host1)
@@ -42,8 +42,17 @@ RSpec.describe Kanrisuru::Remote::Cluster do
42
42
  expect(cluster.hosts).to include(host2)
43
43
  end
44
44
 
45
+ it 'fails to add host to a cluster' do
46
+ cluster = described_class.new
47
+ expect { cluster << 1 }.to raise_error(ArgumentError)
48
+ expect { cluster << 'hello' }.to raise_error(ArgumentError)
49
+ expect { cluster << ['host'] }.to raise_error(ArgumentError)
50
+
51
+ expect(cluster.count).to eq(0)
52
+ end
53
+
45
54
  it 'removes a host from a cluster' do
46
- cluster = Kanrisuru::Remote::Cluster.new(host1, host2)
55
+ cluster = described_class.new(host1, host2)
47
56
  expect(cluster.count).to eq(2)
48
57
 
49
58
  cluster.delete(host2)
@@ -54,4 +63,4 @@ RSpec.describe Kanrisuru::Remote::Cluster do
54
63
  expect(cluster.count).to eq(0)
55
64
  expect(cluster.hosts).not_to include(host1)
56
65
  end
57
- end
66
+ end
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Cpu do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ context 'metal' do
15
+ let(:host) do
16
+ Kanrisuru::Remote::Host.new(
17
+ host: 'metal-host',
18
+ username: 'ubuntu',
19
+ keys: ['id_rsa']
20
+ )
21
+ end
22
+
23
+ before do
24
+ StubNetwork.stub_command!(:lscpu) do |_args|
25
+ struct = Kanrisuru::Core::System::CPUArchitecture.new
26
+ struct.architecture = 'x86_64'
27
+ struct.cores = 48
28
+ struct.byte_order = 'Little Endian'
29
+ struct.address_sizes = ['46 bits physical', '48 bits virtual']
30
+ struct.operation_modes = %w[32-bit 64-bit]
31
+ struct.online_cpus = 0
32
+ struct.threads_per_core = 2
33
+ struct.cores_per_socket = 12
34
+ struct.sockets = 2
35
+ struct.numa_mode = nil
36
+ struct.vendor_id = 'GenuineIntel'
37
+ struct.cpu_family = 6
38
+ struct.model = 63
39
+ struct.model_name = 'Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz'
40
+ struct.stepping = 2
41
+ struct.cpu_mhz = 1200.16
42
+ struct.cpu_max_mhz = 3300.0
43
+ struct.cpu_min_mhz = 1200.0
44
+ struct.bogo_mips = nil
45
+ struct.virtualization = 'VT-x'
46
+ struct.hypervisor_vendor = nil
47
+ struct.virtualization_type = nil
48
+ struct.l1d_cache = '768 KiB'
49
+ struct.l1i_cache = '768 KiB'
50
+ struct.l2_cache = '6 MiB'
51
+ struct.l3_cache = '60 MiB'
52
+ struct.numa_nodes = 2
53
+ struct.vulnerabilities = [
54
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Itlb multihit',
55
+ 'KVM: Mitigation: Split huge pages'),
56
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('L1tf',
57
+ 'Mitigation; PTE Inversion; VMX conditional cache flushes, SMT vulnerable'),
58
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Mds',
59
+ 'Mitigation; Clear CPU buffers; SMT vulnerable'),
60
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Meltdown', 'Mitigation; PTI'),
61
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spec store bypass',
62
+ 'Mitigation; Speculative Store Bypass disabled via prctl and seccomp'),
63
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v1',
64
+ 'Mitigation; usercopy/swapgs barriers and __user pointer sanitization'),
65
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Spectre v2',
66
+ 'Mitigation; Full generic retpoline, IBPB conditional, IBRS_FW, STIBP conditional, RSB filling'),
67
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Srbds', 'Not affected'),
68
+ Kanrisuru::Core::System::CPUArchitectureVulnerability.new('Tsx async abort', 'Not affected')
69
+ ]
70
+ struct.flags = %w[fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge
71
+ mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm cpuid_fault epb invpcid_single pti intel_ppin ssbd ibrs ibpb stibp tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc dtherm ida arat pln pts md_clear flush_l1d]
72
+ struct
73
+ end
74
+ end
75
+
76
+ after do
77
+ StubNetwork.unstub_command!(:lscpu)
78
+ end
79
+
80
+ it 'gets host cpu attributes' do
81
+ expect(host.cpu.architecture).to eq('x86_64')
82
+ expect(host.cpu.cores).to eq(48)
83
+ expect(host.cpu.byte_order).to eq('Little Endian')
84
+ expect(host.cpu.address_sizes).to eq(['46 bits physical', '48 bits virtual'])
85
+ expect(host.cpu.threads_per_core).to eq(2)
86
+ expect(host.cpu.cores_per_socket).to eq(12)
87
+ expect(host.cpu.sockets).to eq(2)
88
+ expect(host.cpu.vendor_id).to eq('GenuineIntel')
89
+ expect(host.cpu.cpu_family).to eq(6)
90
+ expect(host.cpu.model).to eq(63)
91
+ expect(host.cpu.model_name).to eq('Intel(R) Xeon(R) CPU E5-2680 v3 @ 2.50GHz')
92
+ expect(host.cpu.cpu_mhz).to eq(1200.16)
93
+ expect(host.cpu.cpu_max_mhz).to eq(3300.0)
94
+ expect(host.cpu.cpu_min_mhz).to eq(1200.0)
95
+ expect(host.cpu.hypervisor).to be_nil
96
+ expect(host.cpu.virtualization_type).to be_nil
97
+ # expect(host.cpu.l1d_cache).to eq("768 KiB")
98
+ # expect(host.cpu.l1i_cache).to eq("768 KiB")
99
+ # expect(host.cpu.l2_cache).to eq("6 MiB")
100
+ # expect(host.cpu.l3_cache).to eq("60 MiB")
101
+ expect(host.cpu.numa_nodes).to eq(2)
102
+ end
103
+ end
104
+ end