kanrisuru 0.12.1 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/result_spec.rb +150 -0
- data/spec/{hosts.json → helper/hosts.json} +0 -0
- data/spec/helper/simplecov.rb +21 -0
- data/spec/helper/test_hosts.rb +1 -1
- data/spec/integration/core/apt/debian_spec.rb +9 -0
- data/spec/integration/core/apt/ubuntu_spec.rb +9 -0
- data/spec/integration/core/archive/centos_spec.rb +9 -0
- data/spec/integration/core/archive/debian_spec.rb +9 -0
- data/spec/integration/core/archive/fedora_spec.rb +9 -0
- data/spec/integration/core/archive/opensuse_spec.rb +9 -0
- data/spec/integration/core/archive/rhel_spec.rb +9 -0
- data/spec/integration/core/archive/sles_spec.rb +9 -0
- data/spec/integration/core/archive/ubuntu_spec.rb +9 -0
- data/spec/integration/core/disk/centos_spec.rb +9 -0
- data/spec/integration/core/disk/debian_spec.rb +9 -0
- data/spec/integration/core/disk/fedora_spec.rb +9 -0
- data/spec/integration/core/disk/opensuse_spec.rb +9 -0
- data/spec/integration/core/disk/rhel_spec.rb +9 -0
- data/spec/integration/core/disk/sles_spec.rb +9 -0
- data/spec/integration/core/disk/ubuntu_spec.rb +9 -0
- data/spec/integration/core/dmi/centos_spec.rb +9 -0
- data/spec/integration/core/dmi/debian_spec.rb +9 -0
- data/spec/integration/core/dmi/fedora_spec.rb +9 -0
- data/spec/integration/core/dmi/opensuse_spec.rb +9 -0
- data/spec/integration/core/dmi/rhel_spec.rb +9 -0
- data/spec/integration/core/dmi/sles_spec.rb +9 -0
- data/spec/integration/core/dmi/ubuntu_spec.rb +9 -0
- data/spec/integration/core/file/centos_spec.rb +9 -0
- data/spec/integration/core/file/debian_spec.rb +9 -0
- data/spec/integration/core/file/fedora_spec.rb +9 -0
- data/spec/integration/core/file/opensuse_spec.rb +9 -0
- data/spec/integration/core/file/rhel_spec.rb +9 -0
- data/spec/integration/core/file/sles_spec.rb +9 -0
- data/spec/integration/core/file/ubuntu_spec.rb +9 -0
- data/spec/integration/core/find/centos_spec.rb +9 -0
- data/spec/integration/core/find/debian_spec.rb +9 -0
- data/spec/integration/core/find/fedora_spec.rb +9 -0
- data/spec/integration/core/find/opensuse_spec.rb +9 -0
- data/spec/integration/core/find/rhel_spec.rb +9 -0
- data/spec/integration/core/find/sles_spec.rb +9 -0
- data/spec/integration/core/find/ubuntu_spec.rb +9 -0
- data/spec/integration/core/group/centos_spec.rb +9 -0
- data/spec/integration/core/group/debian_spec.rb +9 -0
- data/spec/integration/core/group/fedora_spec.rb +9 -0
- data/spec/integration/core/group/opensuse_spec.rb +9 -0
- data/spec/integration/core/group/rhel_spec.rb +9 -0
- data/spec/integration/core/group/sles_spec.rb +9 -0
- data/spec/integration/core/group/ubuntu_spec.rb +9 -0
- data/spec/integration/core/ip/centos_spec.rb +9 -0
- data/spec/integration/core/ip/debian_spec.rb +9 -0
- data/spec/integration/core/ip/fedora_spec.rb +9 -0
- data/spec/integration/core/ip/opensuse_spec.rb +9 -0
- data/spec/integration/core/ip/rhel_spec.rb +9 -0
- data/spec/integration/core/ip/sles_spec.rb +9 -0
- data/spec/integration/core/ip/ubuntu_spec.rb +9 -0
- data/spec/integration/core/path/centos_spec.rb +9 -0
- data/spec/integration/core/path/debian_spec.rb +9 -0
- data/spec/integration/core/path/fedora_spec.rb +9 -0
- data/spec/integration/core/path/opensuse_spec.rb +9 -0
- data/spec/integration/core/path/rhel_spec.rb +9 -0
- data/spec/integration/core/path/sles_spec.rb +9 -0
- data/spec/integration/core/path/ubuntu_spec.rb +9 -0
- data/spec/integration/core/socket/centos_spec.rb +9 -0
- data/spec/integration/core/socket/debian_spec.rb +9 -0
- data/spec/integration/core/socket/fedora_spec.rb +9 -0
- data/spec/integration/core/socket/opensuse_spec.rb +9 -0
- data/spec/integration/core/socket/rhel_spec.rb +9 -0
- data/spec/integration/core/socket/sles_spec.rb +9 -0
- data/spec/integration/core/socket/ubuntu_spec.rb +9 -0
- data/spec/integration/core/stat/centos_spec.rb +9 -0
- data/spec/integration/core/stat/debian_spec.rb +9 -0
- data/spec/integration/core/stat/fedora_spec.rb +9 -0
- data/spec/integration/core/stat/opensuse_spec.rb +9 -0
- data/spec/integration/core/stat/rhel_spec.rb +9 -0
- data/spec/integration/core/stat/sles_spec.rb +9 -0
- data/spec/integration/core/stat/ubuntu_spec.rb +9 -0
- data/spec/integration/core/stream/centos_spec.rb +9 -0
- data/spec/integration/core/stream/debian_spec.rb +9 -0
- data/spec/integration/core/stream/fedora_spec.rb +9 -0
- data/spec/integration/core/stream/opensuse_spec.rb +9 -0
- data/spec/integration/core/stream/rhel_spec.rb +9 -0
- data/spec/integration/core/stream/sles_spec.rb +9 -0
- data/spec/integration/core/stream/ubuntu_spec.rb +9 -0
- data/spec/integration/core/system/centos_spec.rb +9 -0
- data/spec/integration/core/system/debian_spec.rb +9 -0
- data/spec/integration/core/system/fedora_spec.rb +9 -0
- data/spec/integration/core/system/opensuse_spec.rb +9 -0
- data/spec/integration/core/system/rhel_spec.rb +9 -0
- data/spec/integration/core/system/sles_spec.rb +9 -0
- data/spec/integration/core/system/ubuntu_spec.rb +9 -0
- data/spec/integration/core/transfer/centos_spec.rb +9 -0
- data/spec/integration/core/transfer/debian_spec.rb +9 -0
- data/spec/integration/core/transfer/fedora_spec.rb +9 -0
- data/spec/integration/core/transfer/opensuse_spec.rb +9 -0
- data/spec/integration/core/transfer/rhel_spec.rb +9 -0
- data/spec/integration/core/transfer/sles_spec.rb +9 -0
- data/spec/integration/core/transfer/ubuntu_spec.rb +9 -0
- data/spec/integration/core/user/centos_spec.rb +9 -0
- data/spec/integration/core/user/debian_spec.rb +9 -0
- data/spec/integration/core/user/fedora_spec.rb +9 -0
- data/spec/integration/core/user/opensuse_spec.rb +9 -0
- data/spec/integration/core/user/rhel_spec.rb +9 -0
- data/spec/integration/core/user/sles_spec.rb +9 -0
- data/spec/integration/core/user/ubuntu_spec.rb +9 -0
- data/spec/integration/core/yum/centos_spec.rb +9 -0
- data/spec/integration/core/yum/fedora_spec.rb +9 -0
- data/spec/integration/core/yum/rhel_spec.rb +9 -0
- data/spec/integration/core/zypper/opensuse_spec.rb +9 -0
- data/spec/integration/core/zypper/sles_spec.rb +9 -0
- data/spec/integration/remote/cluster/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/cpu/centos_spec.rb +9 -0
- data/spec/integration/remote/cpu/debian_spec.rb +9 -0
- data/spec/integration/remote/cpu/fedora_spec.rb +9 -0
- data/spec/integration/remote/cpu/opensuse_spec.rb +9 -0
- data/spec/integration/remote/cpu/rhel_spec.rb +9 -0
- data/spec/integration/remote/cpu/sles_spec.rb +9 -0
- data/spec/integration/remote/cpu/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/env/centos_spec.rb +9 -0
- data/spec/integration/remote/env/debian_spec.rb +9 -0
- data/spec/integration/remote/env/fedora_spec.rb +9 -0
- data/spec/integration/remote/env/opensuse_spec.rb +9 -0
- data/spec/integration/remote/env/rhel_spec.rb +9 -0
- data/spec/integration/remote/env/sles_spec.rb +9 -0
- data/spec/integration/remote/env/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/fstab/centos_spec.rb +9 -0
- data/spec/integration/remote/fstab/debian_spec.rb +9 -0
- data/spec/integration/remote/fstab/fedora_spec.rb +9 -0
- data/spec/integration/remote/fstab/opensuse_spec.rb +9 -0
- data/spec/integration/remote/fstab/rhel_spec.rb +9 -0
- data/spec/integration/remote/fstab/sles_spec.rb +9 -0
- data/spec/integration/remote/fstab/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/host/centos_spec.rb +9 -0
- data/spec/integration/remote/host/debian_spec.rb +9 -0
- data/spec/integration/remote/host/fedora_spec.rb +9 -0
- data/spec/integration/remote/host/opensuse_spec.rb +9 -0
- data/spec/integration/remote/host/rhel_spec.rb +9 -0
- data/spec/integration/remote/host/sles_spec.rb +9 -0
- data/spec/integration/remote/host/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/memory/centos_spec.rb +9 -0
- data/spec/integration/remote/memory/debian_spec.rb +9 -0
- data/spec/integration/remote/memory/fedora_spec.rb +9 -0
- data/spec/integration/remote/memory/opensuse_spec.rb +9 -0
- data/spec/integration/remote/memory/rhel_spec.rb +9 -0
- data/spec/integration/remote/memory/sles_spec.rb +9 -0
- data/spec/integration/remote/memory/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/os/centos_spec.rb +9 -0
- data/spec/integration/remote/os/debian_spec.rb +9 -0
- data/spec/integration/remote/os/fedora_spec.rb +9 -0
- data/spec/integration/remote/os/opensuse_spec.rb +9 -0
- data/spec/integration/remote/os/rhel_spec.rb +9 -0
- data/spec/integration/remote/os/sles_spec.rb +9 -0
- data/spec/integration/remote/os/ubuntu_spec.rb +9 -0
- data/spec/integration/remote/remote_file/centos_spec.rb +9 -0
- data/spec/integration/remote/remote_file/debian_spec.rb +9 -0
- data/spec/integration/remote/remote_file/fedora_spec.rb +9 -0
- data/spec/integration/remote/remote_file/opensuse_spec.rb +9 -0
- data/spec/integration/remote/remote_file/rhel_spec.rb +9 -0
- data/spec/integration/remote/remote_file/sles_spec.rb +9 -0
- data/spec/integration/remote/remote_file/ubuntu_spec.rb +9 -0
- data/spec/spec_helper.rb +2 -11
- data/spec/support/shared_examples/integration/core/apt.rb +117 -0
- data/spec/support/shared_examples/integration/core/archive.rb +221 -0
- data/spec/support/shared_examples/integration/core/disk.rb +91 -0
- data/spec/support/shared_examples/integration/core/dmi.rb +34 -0
- data/spec/support/shared_examples/integration/core/file.rb +357 -0
- data/spec/support/shared_examples/integration/core/find.rb +50 -0
- data/spec/support/shared_examples/integration/core/group.rb +62 -0
- data/spec/support/shared_examples/integration/core/ip.rb +68 -0
- data/spec/support/shared_examples/integration/core/path.rb +90 -0
- data/spec/support/shared_examples/integration/core/socket.rb +27 -0
- data/spec/support/shared_examples/integration/core/stat.rb +95 -0
- data/spec/support/shared_examples/integration/core/stream.rb +112 -0
- data/spec/support/shared_examples/integration/core/system.rb +155 -0
- data/spec/support/shared_examples/integration/core/transfer.rb +101 -0
- data/spec/support/shared_examples/integration/core/user.rb +72 -0
- data/spec/support/shared_examples/integration/core/yum.rb +115 -0
- data/spec/support/shared_examples/integration/core/zypper.rb +196 -0
- data/spec/{integration/remote/cluster_spec.rb → support/shared_examples/integration/remote/cluster.rb} +2 -2
- data/spec/support/shared_examples/integration/remote/cpu.rb +38 -0
- data/spec/support/shared_examples/integration/remote/env_spec.rb +33 -0
- data/spec/support/shared_examples/integration/remote/fstab.rb +89 -0
- data/spec/support/shared_examples/integration/remote/host.rb +65 -0
- data/spec/support/shared_examples/integration/remote/memory.rb +27 -0
- data/spec/support/shared_examples/integration/remote/os.rb +60 -0
- data/spec/support/shared_examples/integration/remote/remote_file.rb +172 -0
- metadata +185 -29
- data/spec/integration/core/apt_spec.rb +0 -119
- data/spec/integration/core/archive_spec.rb +0 -223
- data/spec/integration/core/disk_spec.rb +0 -93
- data/spec/integration/core/dmi_spec.rb +0 -36
- data/spec/integration/core/file_spec.rb +0 -359
- data/spec/integration/core/find_spec.rb +0 -52
- data/spec/integration/core/group_spec.rb +0 -64
- data/spec/integration/core/ip_spec.rb +0 -70
- data/spec/integration/core/path_spec.rb +0 -92
- data/spec/integration/core/socket_spec.rb +0 -29
- data/spec/integration/core/stat_spec.rb +0 -97
- data/spec/integration/core/stream_spec.rb +0 -114
- data/spec/integration/core/system_spec.rb +0 -142
- data/spec/integration/core/transfer_spec.rb +0 -103
- data/spec/integration/core/user_spec.rb +0 -74
- data/spec/integration/core/yum_spec.rb +0 -117
- data/spec/integration/core/zypper_spec.rb +0 -198
- data/spec/integration/remote/cpu_spec.rb +0 -40
- data/spec/integration/remote/env_spec.rb +0 -35
- data/spec/integration/remote/fstab_spec.rb +0 -91
- data/spec/integration/remote/host_spec.rb +0 -67
- data/spec/integration/remote/memory_spec.rb +0 -29
- data/spec/integration/remote/os_spec.rb +0 -62
- data/spec/integration/remote/remote_file_spec.rb +0 -174
- data/spec/zz_reboot_spec.rb +0 -46
@@ -0,0 +1,196 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'zypper' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host) do
|
8
|
+
Kanrisuru::Remote::Host.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
host.disconnect
|
17
|
+
end
|
18
|
+
|
19
|
+
def find_repo(host, repo_name)
|
20
|
+
repos = host.zypper('repos').data
|
21
|
+
repos.find { |repo| repo.alias == repo_name }
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'lists repos' do
|
25
|
+
result = host.zypper('repos')
|
26
|
+
expect(result).to be_success
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'installs a package' do
|
30
|
+
host.su('root')
|
31
|
+
result = host.zypper('install', packages: 'nginx')
|
32
|
+
expect(result).to be_success
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'installs multiple packages' do
|
36
|
+
host.su('root')
|
37
|
+
result = host.zypper('install', packages: %w[curl nginx])
|
38
|
+
expect(result).to be_success
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'removes a package' do
|
42
|
+
host.su('root')
|
43
|
+
result = host.zypper('remove', packages: ['nginx'])
|
44
|
+
expect(result).to be_success
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'lists updates' do
|
48
|
+
result = host.zypper('list-updates')
|
49
|
+
expect(result).to be_success
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'lists patches' do
|
53
|
+
result = host.zypper('list-patches')
|
54
|
+
expect(result).to be_success
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'lists important and secure patches' do
|
58
|
+
result = host.zypper('list-patches', category: ['security'], severity: %w[important moderate])
|
59
|
+
expect(result).to be_success
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'lists patch check counts' do
|
63
|
+
result = host.zypper('patch-check')
|
64
|
+
expect(result).to be_success
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'updates a package' do
|
68
|
+
host.su('root')
|
69
|
+
result = host.zypper('update', packages: 'curl')
|
70
|
+
expect(result).to be_success
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'gets info for one package' do
|
74
|
+
result = host.zypper('info', packages: 'curl')
|
75
|
+
expect(result).to be_success
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'gets info for multiple packages' do
|
79
|
+
result = host.zypper('info', packages: %w[curl wget git sudo])
|
80
|
+
expect(result).to be_success
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'gets info for type' do
|
84
|
+
result = host.zypper('info', type: 'package', packages: 'gc*')
|
85
|
+
expect(result).to be_success
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'patches system' do
|
89
|
+
host.su('root')
|
90
|
+
result = host.zypper('patch', severity: 'moderate')
|
91
|
+
expect(result).to be_success
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'performs a dist-upgrade' do
|
95
|
+
case os_name
|
96
|
+
when 'opensuse'
|
97
|
+
host.su('root')
|
98
|
+
result = host.zypper('dist-upgrade', dry_run: true)
|
99
|
+
expect(result).to be_success
|
100
|
+
when 'sles'
|
101
|
+
host.su('root')
|
102
|
+
result = host.zypper('dist-upgrade', dry_run: true, auto_agree_with_licenses: true)
|
103
|
+
expect(result).to be_success
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'searches for single package with match' do
|
108
|
+
result = host.zypper('search', packages: 'gc*', sort_by_name: true)
|
109
|
+
expect(result).to be_success
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'searches for multiple packages' do
|
113
|
+
result = host.zypper('search', packages: %w[nginx ffmpeg], sort_by_repo: true)
|
114
|
+
expect(result).to be_success
|
115
|
+
end
|
116
|
+
|
117
|
+
it 'manages a repo' do
|
118
|
+
repo_alias = 'graphics'
|
119
|
+
if os_name == 'opensuse'
|
120
|
+
repo_name = 'Graphics Project (openSUSE_Leap_15.2)'
|
121
|
+
repo_uri = 'https://download.opensuse.org/repositories/graphics/openSUSE_Leap_15.2/'
|
122
|
+
else
|
123
|
+
repo_name = 'Graphics Project (openSUSE_Leap_15.3)'
|
124
|
+
repo_uri = 'https://download.opensuse.org/repositories/graphics/openSUSE_Leap_15.3/'
|
125
|
+
end
|
126
|
+
|
127
|
+
url = "#{repo_uri}/#{repo_alias}.repo"
|
128
|
+
|
129
|
+
host.su('root')
|
130
|
+
result = host.zypper('addrepo', repos: url)
|
131
|
+
expect(result).to be_success
|
132
|
+
|
133
|
+
repo = find_repo(host, repo_alias)
|
134
|
+
|
135
|
+
expect(repo).to be_instance_of(Kanrisuru::Core::Zypper::Repo)
|
136
|
+
expect(repo.uri).to eq(repo_uri)
|
137
|
+
expect(repo.name).to eq(repo_name)
|
138
|
+
|
139
|
+
new_repo_alias = 'graphics-repo'
|
140
|
+
result = host.zypper('renamerepo', repo: repo_alias, alias: new_repo_alias)
|
141
|
+
expect(result).to be_success
|
142
|
+
repo = find_repo(host, new_repo_alias)
|
143
|
+
expect(repo.alias).to eq(new_repo_alias)
|
144
|
+
|
145
|
+
result = host.zypper('modifyrepo', repos: new_repo_alias, disable: true)
|
146
|
+
expect(result).to be_success
|
147
|
+
repo = find_repo(host, new_repo_alias)
|
148
|
+
expect(repo.enabled).to be_falsey
|
149
|
+
|
150
|
+
result = host.zypper('removerepo', repos: new_repo_alias)
|
151
|
+
expect(result).to be_success
|
152
|
+
|
153
|
+
repo = find_repo(host, new_repo_alias)
|
154
|
+
expect(repo).to be_nil
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'refreshes repos' do
|
158
|
+
host.su('root')
|
159
|
+
result = host.zypper('refresh')
|
160
|
+
expect(result).to be_success
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'cleans repo caches' do
|
164
|
+
host.su('root')
|
165
|
+
result = host.zypper('clean')
|
166
|
+
expect(result).to be_success
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'lists services' do
|
170
|
+
result = host.zypper('services')
|
171
|
+
expect(result).to be_success
|
172
|
+
end
|
173
|
+
|
174
|
+
it 'refreshes services' do
|
175
|
+
host.su('root')
|
176
|
+
result = host.zypper('refresh-services')
|
177
|
+
expect(result).to be_success
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'manages locks' do
|
181
|
+
host.su('root')
|
182
|
+
result = host.zypper('addlock', lock: 'nginx', type: 'package')
|
183
|
+
expect(result).to be_success
|
184
|
+
|
185
|
+
result = host.zypper('locks')
|
186
|
+
expect(result).to be_success
|
187
|
+
|
188
|
+
lock = result.first
|
189
|
+
expect(lock.name).to eq('nginx')
|
190
|
+
expect(lock.type).to eq('package')
|
191
|
+
|
192
|
+
result = host.zypper('removelock', lock: 'nginx')
|
193
|
+
expect(result).to be_success
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
|
-
RSpec.
|
6
|
-
context
|
5
|
+
RSpec.shared_examples 'cluster' do |os_name, _host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
7
|
it 'gets hostname for cluster' do
|
8
8
|
cluster = described_class.new({
|
9
9
|
host: 'localhost',
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'cpu' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host) do
|
8
|
+
Kanrisuru::Remote::Host.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
host.disconnect
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'gets cpu details' do
|
20
|
+
expect(host.cpu.cores).to eq(1)
|
21
|
+
expect(host.cpu.total).to eq(1)
|
22
|
+
expect(host.cpu.count).to eq(1)
|
23
|
+
|
24
|
+
expect(host.cpu.threads_per_core).to eq(1)
|
25
|
+
expect(host.cpu.cores_per_socket).to eq(1)
|
26
|
+
expect(host.cpu.sockets).to eq(1)
|
27
|
+
|
28
|
+
expect(host.cpu.hyperthreading?).to eq(false)
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'gets cpu load average' do
|
32
|
+
expect(host.cpu.load_average).to be_instance_of(Array)
|
33
|
+
expect(host.cpu.load_average1).to be_instance_of(Float)
|
34
|
+
expect(host.cpu.load_average5).to be_instance_of(Float)
|
35
|
+
expect(host.cpu.load_average15).to be_instance_of(Float)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'env' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host) do
|
8
|
+
Kanrisuru::Remote::Host.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
host.disconnect
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'sets env var' do
|
20
|
+
host.env['HELLO'] = 'world'
|
21
|
+
host.env['KANRISURU'] = 'manage'
|
22
|
+
|
23
|
+
expect(host.env['KANRISURU']).to eq('manage')
|
24
|
+
expect(host.env.to_s).to eq('export HELLO=world; export KANRISURU=manage;')
|
25
|
+
expect(host.env.to_h).to eq({ 'HELLO' => 'world', 'KANRISURU' => 'manage' })
|
26
|
+
|
27
|
+
command = Kanrisuru::Command.new('echo $KANRISURU $HELLO')
|
28
|
+
host.execute_shell(command)
|
29
|
+
|
30
|
+
expect(command.to_s).to eq('manage world')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.shared_examples 'fstab' do |os_name, host_json, _spec_dir|
|
4
|
+
context "with #{os_name}" do
|
5
|
+
let(:host) do
|
6
|
+
Kanrisuru::Remote::Host.new(
|
7
|
+
host: host_json['hostname'],
|
8
|
+
username: host_json['username'],
|
9
|
+
keys: [host_json['ssh_key']]
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
after do
|
14
|
+
host.disconnect
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'outputs string version of fstab' do
|
18
|
+
host.su('root')
|
19
|
+
|
20
|
+
result = host.cat('/etc/fstab')
|
21
|
+
expect(result).to be_success
|
22
|
+
raw_file_lines = []
|
23
|
+
result.each do |line|
|
24
|
+
next if line.match(/^#/) || line == ''
|
25
|
+
|
26
|
+
raw_file_lines << line.split.join(' ')
|
27
|
+
end
|
28
|
+
|
29
|
+
raw_file_output = raw_file_lines.join("\n")
|
30
|
+
expect(raw_file_output).to eq(host.fstab.to_s)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'parses fstab' do
|
34
|
+
host.su('root')
|
35
|
+
fstab = host.fstab
|
36
|
+
|
37
|
+
entry =
|
38
|
+
case os_name
|
39
|
+
when 'opensuse'
|
40
|
+
fstab['/dev/vda3']
|
41
|
+
when 'sles'
|
42
|
+
fstab['/dev/xvda1']
|
43
|
+
else
|
44
|
+
fstab['/dev/vda1']
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(fstab.get_entry(entry.uuid)).to eq(entry)
|
48
|
+
expect(fstab.get_entry(entry.label)).to eq(entry)
|
49
|
+
|
50
|
+
fstab << Kanrisuru::Remote::Fstab::Entry.new(
|
51
|
+
device: '/dev/vda14',
|
52
|
+
mount_point: '/mnt/test',
|
53
|
+
type: 'ext4',
|
54
|
+
opts: { defaults: true },
|
55
|
+
freq: '0',
|
56
|
+
passno: '0'
|
57
|
+
)
|
58
|
+
|
59
|
+
entry = fstab['/dev/vda14']
|
60
|
+
expect(entry.to_s).to eq('/dev/vda14 /mnt/test ext4 defaults 0 0')
|
61
|
+
expect(entry.device).to eq('/dev/vda14')
|
62
|
+
expect(entry.mount_point).to eq('/mnt/test')
|
63
|
+
expect(entry.type).to eq('ext4')
|
64
|
+
expect(entry.opts.to_s).to eq('defaults')
|
65
|
+
expect(entry.freq).to eq('0')
|
66
|
+
expect(entry.passno).to eq('0')
|
67
|
+
|
68
|
+
entry.opts['defaults'] = false
|
69
|
+
entry.opts['user'] = true
|
70
|
+
entry.opts['exec'] = true
|
71
|
+
entry.opts['rw'] = true
|
72
|
+
entry.opts['auto'] = true
|
73
|
+
entry.opts['relatime'] = true
|
74
|
+
entry.opts['async'] = true
|
75
|
+
entry.opts[:nodev] = true
|
76
|
+
entry.opts[:nosuid] = true
|
77
|
+
entry.opts[:owner] = true
|
78
|
+
entry.opts[:group] = true
|
79
|
+
|
80
|
+
entry.mount_point = '/mnt/test3'
|
81
|
+
|
82
|
+
expect(fstab['/dev/vda14'].to_s).to eq '/dev/vda14 /mnt/test3 ext4 ' \
|
83
|
+
'user,exec,rw,auto,relatime,async,nodev,nosuid,owner,group 0 0'
|
84
|
+
|
85
|
+
fstab << '/dev/vda16 /mnt/test2 fat defaults,user,uid=1000,gid=1000 0 0'
|
86
|
+
expect(fstab['/dev/vda16'].to_s).to eq('/dev/vda16 /mnt/test2 fat defaults,user,uid=1000,gid=1000 0 0')
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'host' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host) do
|
8
|
+
described_class.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
host.disconnect
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'can ping localhost' do
|
20
|
+
expect(host.ping?).to eq(true)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'gets hostname' do
|
24
|
+
expect(host.hostname).to eq(host_json['hostname'])
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'changes directories' do
|
28
|
+
expect(host.pwd.path).to eq(host_json['home'])
|
29
|
+
|
30
|
+
host.cd('../')
|
31
|
+
expect(host.pwd.path).to eq('/home')
|
32
|
+
|
33
|
+
host.cd('../')
|
34
|
+
expect(host.pwd.path).to eq('/')
|
35
|
+
|
36
|
+
host.cd('~')
|
37
|
+
|
38
|
+
expect(host.pwd.path).to eq(host_json['home'])
|
39
|
+
|
40
|
+
host.su('root')
|
41
|
+
host.cd('/root/../etc')
|
42
|
+
|
43
|
+
result = host.ls
|
44
|
+
paths = result.map(&:path)
|
45
|
+
|
46
|
+
expect(paths).to include('hosts')
|
47
|
+
expect(paths).to include('shadow')
|
48
|
+
expect(paths).to include('ssh')
|
49
|
+
|
50
|
+
host.cd('default')
|
51
|
+
expect(host.pwd.path).to eq('/etc/default')
|
52
|
+
|
53
|
+
host.su(host_json['username'])
|
54
|
+
|
55
|
+
host.cd('.')
|
56
|
+
expect(host.pwd.path).to eq('/etc/default')
|
57
|
+
|
58
|
+
result = host.ls(path: '/home')
|
59
|
+
expect(result[0].path).to eq(host_json['username'])
|
60
|
+
|
61
|
+
host.cd('/bin')
|
62
|
+
expect(host.pwd.path).to eq('/bin')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'memory' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host_json) { TestHosts.host(os_name) }
|
8
|
+
let(:host) do
|
9
|
+
Kanrisuru::Remote::Host.new(
|
10
|
+
host: host_json['hostname'],
|
11
|
+
username: host_json['username'],
|
12
|
+
keys: [host_json['ssh_key']]
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
host.disconnect
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'gets memory details' do
|
21
|
+
expect(host.memory.total(:gb)).to be >= 0.5
|
22
|
+
expect(host.memory.free(:mb)).to be >= 10.0
|
23
|
+
expect(host.memory.swap).to be_instance_of(Integer)
|
24
|
+
expect(host.memory.swap_free).to be_instance_of(Integer)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.shared_examples 'os' do |os_name, host_json, _spec_dir|
|
6
|
+
context "with #{os_name}" do
|
7
|
+
let(:host) do
|
8
|
+
Kanrisuru::Remote::Host.new(
|
9
|
+
host: host_json['hostname'],
|
10
|
+
username: host_json['username'],
|
11
|
+
keys: [host_json['ssh_key']]
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
host.disconnect
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'detects os specs' do
|
20
|
+
expect(host.os.kernel).to eq(host_json['kernel'])
|
21
|
+
expect(host.os.processor).to eq('x86_64')
|
22
|
+
|
23
|
+
case os_name
|
24
|
+
when 'opensuse'
|
25
|
+
expect(host.os.release).to eq('opensuse_leap')
|
26
|
+
else
|
27
|
+
expect(host.os.release).to eq(os_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
expect(host.os.version).to be > 0.00
|
31
|
+
|
32
|
+
case os_name
|
33
|
+
when 'debian'
|
34
|
+
expect(host.os.version).to eq(10)
|
35
|
+
when 'ubuntu'
|
36
|
+
expect(host.os.version).to eq(18.04)
|
37
|
+
when 'fedora'
|
38
|
+
expect(host.os.version).to eq(32)
|
39
|
+
when 'centos'
|
40
|
+
expect(host.os.version).to eq(7)
|
41
|
+
when 'opensuse'
|
42
|
+
expect(host.os.version).to eq(15.2)
|
43
|
+
when 'rhel'
|
44
|
+
expect(host.os.version).to eq(7.9)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'gets uname' do
|
49
|
+
expect(host.os.uname).to eq(host_json['kernel'])
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'gets uname details' do
|
53
|
+
host.os.uname(
|
54
|
+
kernel_name: true,
|
55
|
+
hardware_platform: true,
|
56
|
+
operating_system: true
|
57
|
+
)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
module Remote
|
5
|
+
Class.new(File) do
|
6
|
+
READ_FILE_SIZE = 25_000
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec.shared_examples 'remote_file' do |os_name, host_json, spec_dir|
|
12
|
+
context "with #{os_name}" do
|
13
|
+
before(:all) do
|
14
|
+
host = Kanrisuru::Remote::Host.new(
|
15
|
+
host: host_json['hostname'],
|
16
|
+
username: host_json['username'],
|
17
|
+
keys: [host_json['ssh_key']]
|
18
|
+
)
|
19
|
+
|
20
|
+
host.mkdir(spec_dir, silent: true)
|
21
|
+
host.disconnect
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:host) do
|
25
|
+
Kanrisuru::Remote::Host.new(
|
26
|
+
host: host_json['hostname'],
|
27
|
+
username: host_json['username'],
|
28
|
+
keys: [host_json['ssh_key']]
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
after do
|
33
|
+
host.disconnect
|
34
|
+
end
|
35
|
+
|
36
|
+
after(:all) do
|
37
|
+
host = Kanrisuru::Remote::Host.new(
|
38
|
+
host: host_json['hostname'],
|
39
|
+
username: host_json['username'],
|
40
|
+
keys: [host_json['ssh_key']]
|
41
|
+
)
|
42
|
+
|
43
|
+
host.rmdir(spec_dir)
|
44
|
+
host.disconnect
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'loads a remote file to edit' do
|
48
|
+
file = host.file("#{spec_dir}/remote-file.txt")
|
49
|
+
|
50
|
+
expect(file).to be_instance_of(described_class)
|
51
|
+
expect(file.exists?).to eq(false)
|
52
|
+
expect(file.expand_path).to eq('')
|
53
|
+
|
54
|
+
file.touch
|
55
|
+
|
56
|
+
expect(file.exists?).to eq(true)
|
57
|
+
expect(file.zero?).to eq(true)
|
58
|
+
expect(file.user).to eq(host_json['username'])
|
59
|
+
|
60
|
+
case os_name
|
61
|
+
when 'opensuse', 'sles'
|
62
|
+
expect(file.group).to eq('users')
|
63
|
+
else
|
64
|
+
expect(file.group).to eq(host_json['username'])
|
65
|
+
end
|
66
|
+
|
67
|
+
expect(file.expand_path).to eq("#{spec_dir}/remote-file.txt")
|
68
|
+
|
69
|
+
file.append do |f|
|
70
|
+
f << 'Hello world'
|
71
|
+
f << 'this is a test!'
|
72
|
+
end
|
73
|
+
|
74
|
+
lines = file.map { |line| line }
|
75
|
+
expect(lines).to eq(['Hello world', 'this is a test!'])
|
76
|
+
expect(file.zero?).to eq(false)
|
77
|
+
|
78
|
+
file.prepend do |f|
|
79
|
+
f << 'Lines exist'
|
80
|
+
f << 'at the beginning...'
|
81
|
+
end
|
82
|
+
|
83
|
+
expect(file[0]).to eq('Lines exist')
|
84
|
+
expect(file[3]).to eq('this is a test!')
|
85
|
+
|
86
|
+
lines = file.map { |line| line }
|
87
|
+
expect(lines).to eq(['Lines exist', 'at the beginning...', 'Hello world', 'this is a test!'])
|
88
|
+
|
89
|
+
expect(file.delete).to eq(true)
|
90
|
+
expect(file.exists?).to eq(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'finds and updates file' do
|
94
|
+
file = host.file("#{spec_dir}/hosts.conf.test")
|
95
|
+
|
96
|
+
file.touch
|
97
|
+
|
98
|
+
file.write do |f|
|
99
|
+
f << '127.0.0.1 localhost'
|
100
|
+
f << '127.0.1.1 ubuntu'
|
101
|
+
f << ''
|
102
|
+
f << '# The following lines are desirable for IPv6 capable hosts'
|
103
|
+
f << '::1 ip6-localhost ip6-loopback'
|
104
|
+
f << 'fe00::0 ip6-localnet'
|
105
|
+
f << 'ff00::0 ip6-mcastprefix'
|
106
|
+
f << 'ff02::1 ip6-allnodes'
|
107
|
+
f << 'ff02::2 ip6-allrouters'
|
108
|
+
f << 'ff02::3 ip6-allhosts'
|
109
|
+
end
|
110
|
+
|
111
|
+
expect(file[2]).to eq('')
|
112
|
+
file.find_and_append(/^127.0.1.1 ubuntu/, '8.8.8.8 rickroll.com')
|
113
|
+
expect(file[2]).to eq('8.8.8.8 rickroll.com')
|
114
|
+
|
115
|
+
expect(file[1]).to eq('127.0.1.1 ubuntu')
|
116
|
+
file.find_and_prepend(/^127.0.1.1 ubuntu/, '1.1.1.1 nevergoingtoletyoudown.io')
|
117
|
+
expect(file[1]).to eq('1.1.1.1 nevergoingtoletyoudown.io')
|
118
|
+
|
119
|
+
file.prepend do |f|
|
120
|
+
f << '# Generated by Kanrisuru'
|
121
|
+
end
|
122
|
+
|
123
|
+
file.find_and_replace_line(/#/, '# Rick Astley was here')
|
124
|
+
expect(file[0]).to eq('# Rick Astley was here')
|
125
|
+
expect(file[6]).to eq('# Rick Astley was here')
|
126
|
+
|
127
|
+
file.find_and_replace_value(/\slocalhost/, ' nevergoingtogiveyouup.biz')
|
128
|
+
expect(file[1]).to eq('127.0.0.1 nevergoingtogiveyouup.biz')
|
129
|
+
|
130
|
+
file.find_and_remove(/^::/)
|
131
|
+
file.find_and_remove(/^ff/)
|
132
|
+
file.find_and_remove(/^fe/)
|
133
|
+
|
134
|
+
expect(file.lines).to eq(7)
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'iterates with chunking' do
|
138
|
+
file = host.file("#{spec_dir}/remote-file-large.txt")
|
139
|
+
|
140
|
+
expect(file.exists?).to eq(false)
|
141
|
+
|
142
|
+
file.touch
|
143
|
+
|
144
|
+
file.write do |f|
|
145
|
+
(0...50_000).each do |i|
|
146
|
+
f << "Line: #{i}"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
line = file.find do |f|
|
151
|
+
f == 'Line: 1111'
|
152
|
+
end
|
153
|
+
|
154
|
+
expect(line).to eq('Line: 1111')
|
155
|
+
|
156
|
+
expect(file[0]).to eq('Line: 0')
|
157
|
+
expect(file[5]).to eq('Line: 5')
|
158
|
+
expect(file[28_445]).to eq('Line: 28445')
|
159
|
+
expect(file[49_999]).to eq('Line: 49999')
|
160
|
+
expect { file[50_000] }.to raise_error(ArgumentError)
|
161
|
+
|
162
|
+
file.prepend do |f|
|
163
|
+
f << 'Hello large file'
|
164
|
+
end
|
165
|
+
|
166
|
+
expect(file[0]).to eq('Hello large file')
|
167
|
+
expect(file[1]).to eq('Line: 0')
|
168
|
+
expect(file[28_446]).to eq('Line: 28445')
|
169
|
+
expect(file[50_000]).to eq('Line: 49999')
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|