kanrisuru 0.8.23 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/CHANGELOG.md +36 -19
- data/README.md +1 -0
- data/kanrisuru.gemspec +2 -1
- data/lib/kanrisuru/core/archive.rb +6 -5
- data/lib/kanrisuru/remote/cluster.rb +33 -1
- data/lib/kanrisuru/remote/cpu.rb +3 -3
- data/lib/kanrisuru/remote/env.rb +8 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/archive_spec.rb +194 -0
- data/spec/functional/remote/cluster_spec.rb +57 -0
- data/spec/functional/remote/env_spec.rb +50 -0
- data/spec/helper/stub_network.rb +25 -1
- data/spec/{functional → integration}/os_package_spec.rb +0 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/unit/command_spec.rb +31 -0
- data/spec/unit/core/apt_spec.rb +20 -0
- data/spec/unit/core/archive_spec.rb +20 -0
- data/spec/unit/core/disk_spec.rb +23 -0
- data/spec/unit/core/dmi_spec.rb +20 -0
- data/spec/unit/core/file_spec.rb +35 -0
- data/spec/unit/core/find_spec.rb +20 -0
- data/spec/unit/core/group_spec.rb +24 -0
- data/spec/unit/core/ip_spec.rb +20 -0
- data/spec/unit/core/path_spec.rb +25 -0
- data/spec/unit/core/socket_spec.rb +20 -0
- data/spec/unit/core/stat_spec.rb +27 -0
- data/spec/unit/core/system_spec.rb +35 -0
- data/spec/unit/core/transfer_spec.rb +22 -0
- data/spec/unit/core/user_spec.rb +25 -0
- data/spec/unit/core/yum_spec.rb +20 -0
- data/spec/unit/core/zypper_spec.rb +20 -0
- data/spec/unit/mode_spec.rb +31 -0
- data/spec/unit/remote/cluster_spec.rb +34 -0
- data/spec/unit/remote/cpu_spec.rb +50 -0
- data/spec/unit/remote/env_spec.rb +19 -0
- data/spec/unit/{fstab_spec.rb → remote/fstab_spec.rb} +0 -0
- metadata +27 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40303a0de6eed7d5c10708a31ebf33ee7aed8701a21b3118e9bad5cdc751376b
|
4
|
+
data.tar.gz: 9daec56c51d0a4d6929fbcbbb585744215a61d877993e67453899ccf2db81717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11a75804f677a0b72c88ab944c475646eebe68ed64a1fed15acb349e423215f98ddfcdd626681867eee82bb9092cd349ead6f7a44da142937bf329f300a877b0
|
7
|
+
data.tar.gz: 2605bbf322b06ae28d49d25b7d65970d5e5632527b79e12c6c7d2988173602ed126eab6d263106d866bda146153513573f702e210a36b4a3ee0e812caae06c79
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,57 +1,78 @@
|
|
1
|
-
## Kanrisuru 0.
|
1
|
+
## Kanrisuru 0.10.0 (December 03, 2021) ##
|
2
|
+
* Add `stub_command` and `unstub_command` to mock indvidual command results from a remote server.
|
3
|
+
* Add `count` and `delete` to `Kanrisuru::Remote::Env` class for managing environment variables.
|
4
|
+
* Add unit and functional test cases for `Kanrisuru::Remote::Env`.
|
5
|
+
* Add functional test cases for the `archive` command.
|
6
|
+
* Fix typo bugs in the `archive` command. Fix `--exclude` opt field in `archive` command.
|
7
|
+
* Add unit test cases for `Kanrisuru::Mode` class.
|
8
|
+
|
9
|
+
## Kanrisuru 0.9.2 (November 30, 2021) ##
|
10
|
+
* Add unit test cases for all core commands.
|
11
|
+
* Add unit test cases for `cluster` class.
|
12
|
+
* Add codecov xml output for coverage badge.
|
13
|
+
|
14
|
+
## Kanrisuru 0.9.1 (November 29, 2021) ##
|
15
|
+
* Fix type on `address_sizes` for `Kanrisuru::Remote::Cpu` class.
|
16
|
+
* Add unit test cases for the `cpu` class.
|
17
|
+
|
18
|
+
## Kanrisuru 0.9.0 (November 23, 2021) ##
|
19
|
+
* Add `delete` to `Kanrisuru::Remote::Cluster` class to allow removal of hosts from cluster.
|
20
|
+
* Add functional test cases for remote cluster class.
|
21
|
+
|
22
|
+
## Kanrisuru 0.8.23 (November 19, 2021) ##
|
2
23
|
* Add functional test cases for `yum` command
|
3
24
|
* Add stub by operating system method, with support for `ubuntu` and `centos` os types.
|
4
25
|
* Fix `ArgumentError` typo in yum commands, `erase` and `remove`.
|
5
26
|
|
6
|
-
## Kanrisuru 0.8.22 (November 18, 2021)
|
27
|
+
## Kanrisuru 0.8.22 (November 18, 2021) ##
|
7
28
|
* Add functional test cases for `apt` command
|
8
29
|
|
9
|
-
## Kanrisuru 0.8.21 (November 15, 2021)
|
30
|
+
## Kanrisuru 0.8.21 (November 15, 2021) ##
|
10
31
|
* Fix bug with `Kanrisuru::Mode` class, lookup table had incorrect value for execute only symbolic to numeric field.
|
11
32
|
|
12
|
-
## Kanrisuru 0.8.20 (November 13, 2021)
|
33
|
+
## Kanrisuru 0.8.20 (November 13, 2021) ##
|
13
34
|
* Unstub network requests for full rspec test-suite run
|
14
35
|
|
15
|
-
## Kanrisuru 0.8.19 (October 31, 2021)
|
36
|
+
## Kanrisuru 0.8.19 (October 31, 2021) ##
|
16
37
|
* Add functional test cases for `ss` command.
|
17
38
|
* Enforce contraints on `family` parameter for `ss` command.
|
18
39
|
* Deprecating `string_join_array` in favor of `array_join_string`. Both methods do the same thing, and the `array_join_string` has a better nameing interface; will be removed in the next major release.
|
19
40
|
* Replace `string_join_array` method calls in `apt`, `transfer`, `yum`, and `zypper` with `array_join_string`.
|
20
41
|
|
21
|
-
## Kanrisuru 0.8.18 (October 19, 2021)
|
42
|
+
## Kanrisuru 0.8.18 (October 19, 2021) ##
|
22
43
|
* Add functional test cases for `find` commmand.
|
23
44
|
* Add `regex_type` option for `find` command.
|
24
45
|
* Fix bug with `size` option when using number in a string format, regex testing has been simplified on matching correctness for size with options like `100`, `+100`, `-100M` for comparitive fields.
|
25
46
|
|
26
|
-
## Kanrisuru 0.8.17 (October 16, 2021)
|
47
|
+
## Kanrisuru 0.8.17 (October 16, 2021) ##
|
27
48
|
* Add functional test cases for `transfer` module
|
28
49
|
* Update wget command to accept hash for `headers` opt.
|
29
50
|
|
30
|
-
## Kanrisuru 0.8.16 (October 14, 2021)
|
51
|
+
## Kanrisuru 0.8.16 (October 14, 2021) ##
|
31
52
|
* Add functional test cases for `stream` and `path` modules
|
32
53
|
* Create `expect_command` helper for quick testing on raw command result
|
33
54
|
|
34
|
-
## Kanrisuru 0.8.15 (October 12, 20201)
|
55
|
+
## Kanrisuru 0.8.15 (October 12, 20201) ##
|
35
56
|
* Move functional specs to integration. Anything that performs an actual network request will be under the integrations test.
|
36
57
|
* Create a `StubNetwork` to quickly monkey patch the `Kanrisuru::Remote::Host` to simulate a `Net::SSH` channel request. Will add additional functionality for different simulations later on.
|
37
58
|
* Start with testing the `stat` command as a functional test.
|
38
59
|
|
39
|
-
## Kanrisuru 0.8.14 (October 8, 20201)
|
60
|
+
## Kanrisuru 0.8.14 (October 8, 20201) ##
|
40
61
|
* Update `Kanrisuru::Remote::Cluster` instantiation method to use array splat instead of passing array directly.
|
41
62
|
|
42
|
-
## Kanrisuru 0.8.13 (October 4, 20201)
|
63
|
+
## Kanrisuru 0.8.13 (October 4, 20201) ##
|
43
64
|
* Fix `wc` command. Ensure result parsing is cast to integer values.
|
44
65
|
|
45
|
-
## Kanrisuru 0.8.12 (October 4, 20201)
|
66
|
+
## Kanrisuru 0.8.12 (October 4, 20201) ##
|
46
67
|
* Refactor `rmdir` command to only work on empty directories.
|
47
68
|
|
48
|
-
## Kanrisuru 0.8.11 (October 1, 20201)
|
69
|
+
## Kanrisuru 0.8.11 (October 1, 20201) ##
|
49
70
|
* Allow `Kanrisuru::Mode` as mode type option in mkdir method.
|
50
71
|
|
51
|
-
## Kanrisuru 0.8.10 (August 24, 20201)
|
72
|
+
## Kanrisuru 0.8.10 (August 24, 20201) ##
|
52
73
|
* Fix bug with rspec test case.
|
53
74
|
|
54
|
-
## Kanrisuru 0.8.9 (August 24, 2021)
|
75
|
+
## Kanrisuru 0.8.9 (August 24, 2021) ##
|
55
76
|
* Fix spelling error exception `ArgumentError` in `Kanrisuru::Mode` class.
|
56
77
|
|
57
78
|
## Kanrisuru 0.8.8 (August 21, 2021) ##
|
@@ -121,7 +142,6 @@ cache key to avoid any namespace collisions with the same method name, namely:
|
|
121
142
|
* Deprecating `cpu_info` with replacement of `lscpu`. `cpu_info` will be removed in the next major release.
|
122
143
|
|
123
144
|
## Kanrisuru 0.5.1 (July 29, 2021) ##
|
124
|
-
|
125
145
|
* Unit test cases for core module structs, constants and types.
|
126
146
|
|
127
147
|
## Kanrisuru 0.5.0 (July 29, 2021) ##
|
@@ -158,15 +178,12 @@ cache key to avoid any namespace collisions with the same method name, namely:
|
|
158
178
|
* Replace `cpu` module internal fetching of data from `cpu_info` to `lscpu` struct.
|
159
179
|
|
160
180
|
## Kanrisuru 0.2.9 (July 20, 2021) ##
|
161
|
-
|
162
181
|
* Fix fstab entry from `entry` to `entry[:entry]` in the `for_each`iteration.
|
163
182
|
|
164
183
|
## Kanrisuru 0.2.8 (July 20, 2021) ##
|
165
|
-
|
166
184
|
* Update gem development and runtime depedencies with stricter depencies.
|
167
185
|
|
168
186
|
## Kanrisuru 0.2.7 (July 18, 2021) ##
|
169
|
-
|
170
187
|
* Set opensuse upstream to sles (Suse Enterprise Linux) in `os_family`
|
171
188
|
|
172
189
|
## Kanrisuru 0.2.6 (July 17, 2021) ##
|
data/README.md
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
[![Latest version](https://img.shields.io/gem/v/kanrisuru?style=flat-square)](https://rubygems.org/gems/kanrisuru)
|
2
2
|
[![Latest version](https://img.shields.io/github/license/avamia/kanrisuru)](https://github.com/avamia/kanrisuru/blob/main/LICENSE.txt)
|
3
3
|
![GitHub repo size](https://img.shields.io/github/repo-size/avamia/kanrisuru)
|
4
|
+
![Codecov](https://img.shields.io/codecov/c/gh/avamia/kanrisuru?token=2Q1BE106B2)
|
4
5
|
|
5
6
|
<p align='center'>
|
6
7
|
<img src="https://s3.us-east-2.amazonaws.com/kanrisuru.com/kanrisuru-banner-02.png" width="600" />
|
data/kanrisuru.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.email = 'ryan@avamia.com'
|
10
10
|
gem.license = 'MIT'
|
11
11
|
gem.summary = 'Manage remote servers over ssh with ruby.'
|
12
|
-
gem.description = '
|
12
|
+
gem.description = 'Kanrisuru helps manage remote servers with objected oriented ruby. Results come back as structured data, parsed, prepared and ready .'
|
13
13
|
gem.homepage = 'https://github.com/avamia/kanrisuru'
|
14
14
|
|
15
15
|
gem.required_ruby_version = '>= 2.5.0'
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.add_development_dependency 'rubocop', '~> 1.12'
|
19
19
|
gem.add_development_dependency 'rubocop-rspec', '~> 2.2'
|
20
20
|
gem.add_development_dependency 'simplecov', '~> 0.21'
|
21
|
+
gem.add_development_dependency 'simplecov-cobertura', '~> 2.0'
|
21
22
|
|
22
23
|
gem.add_runtime_dependency 'net-ping', '~> 2.0'
|
23
24
|
gem.add_runtime_dependency 'net-scp', '~> 3.0'
|
@@ -50,7 +50,7 @@ module Kanrisuru
|
|
50
50
|
command.append_flag('--same-owner', opts[:same_owners])
|
51
51
|
command.append_flag('--multi-volume', opts[:multi_volume])
|
52
52
|
command.append_flag('--label', opts[:label])
|
53
|
-
command.append_flag('--one-file-system
|
53
|
+
command.append_flag('--one-file-system', opts[:one_file_system])
|
54
54
|
command.append_flag('--keep-old-files', opts[:keep_old_files])
|
55
55
|
command.append_flag('--skip-old-files', opts[:skip_old_files])
|
56
56
|
command.append_flag('--overwrite', opts[:overwrite])
|
@@ -59,7 +59,7 @@ module Kanrisuru
|
|
59
59
|
command.append_flag('--recursive-unlink', opts[:recursive_unlink])
|
60
60
|
|
61
61
|
if Kanrisuru::Util.present?(paths)
|
62
|
-
paths = paths.instance_of(String) ? [paths] : paths
|
62
|
+
paths = paths.instance_of?(String) ? [paths] : paths
|
63
63
|
command << paths.join(' ')
|
64
64
|
end
|
65
65
|
|
@@ -70,8 +70,10 @@ module Kanrisuru
|
|
70
70
|
command.append_flag('--multi-volume', opts[:multi_volume])
|
71
71
|
|
72
72
|
if Kanrisuru::Util.present?(exclude)
|
73
|
-
|
74
|
-
|
73
|
+
exclude_options = exclude.instance_of?(String) ? [exclude] : exclude
|
74
|
+
exclude_options.each do |exclude_option|
|
75
|
+
command << "--exclude=#{exclude_option}"
|
76
|
+
end
|
75
77
|
end
|
76
78
|
|
77
79
|
if Kanrisuru::Util.present?(paths)
|
@@ -80,7 +82,6 @@ module Kanrisuru
|
|
80
82
|
end
|
81
83
|
|
82
84
|
execute_shell(command)
|
83
|
-
|
84
85
|
Kanrisuru::Result.new(command)
|
85
86
|
when 'append', 'r'
|
86
87
|
command.append_flag('-r')
|
@@ -13,6 +13,10 @@ module Kanrisuru
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
def hosts
|
17
|
+
@hosts.values
|
18
|
+
end
|
19
|
+
|
16
20
|
def [](hostname)
|
17
21
|
@hosts[hostname]
|
18
22
|
end
|
@@ -21,6 +25,10 @@ module Kanrisuru
|
|
21
25
|
add_host(host_opts)
|
22
26
|
end
|
23
27
|
|
28
|
+
def delete(host)
|
29
|
+
remove_host(host)
|
30
|
+
end
|
31
|
+
|
24
32
|
def execute(command)
|
25
33
|
@hosts.map do |host_addr, host|
|
26
34
|
## Need to evaluate each host independently for the command.
|
@@ -81,13 +89,37 @@ module Kanrisuru
|
|
81
89
|
end
|
82
90
|
end
|
83
91
|
|
92
|
+
def remove_host(host)
|
93
|
+
if host.instance_of?(Kanrisuru::Remote::Host)
|
94
|
+
removed = false
|
95
|
+
|
96
|
+
if @hosts.key?(host.host)
|
97
|
+
removed = true
|
98
|
+
@hosts.delete(host.host)
|
99
|
+
end
|
100
|
+
|
101
|
+
removed
|
102
|
+
elsif host.instance_of?(String)
|
103
|
+
removed = false
|
104
|
+
|
105
|
+
if @hosts.key?(host)
|
106
|
+
removed = true
|
107
|
+
@hosts.delete(host)
|
108
|
+
end
|
109
|
+
|
110
|
+
removed
|
111
|
+
else
|
112
|
+
raise ArgumentError, 'Invalid host type'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
84
116
|
def add_host(host_opts)
|
85
117
|
if host_opts.instance_of?(Hash)
|
86
118
|
@hosts[host_opts[:host]] = Kanrisuru::Remote::Host.new(host_opts)
|
87
119
|
elsif host_opts.instance_of?(Kanrisuru::Remote::Host)
|
88
120
|
@hosts[host_opts.host] = host_opts
|
89
121
|
else
|
90
|
-
raise '
|
122
|
+
raise ArgumentError, 'Invalid host option'
|
91
123
|
end
|
92
124
|
end
|
93
125
|
end
|
data/lib/kanrisuru/remote/cpu.rb
CHANGED
@@ -75,8 +75,8 @@ module Kanrisuru
|
|
75
75
|
@cpu_architecture.byte_order
|
76
76
|
end
|
77
77
|
|
78
|
-
def
|
79
|
-
@cpu_architecture.
|
78
|
+
def address_sizes
|
79
|
+
@cpu_architecture.address_sizes
|
80
80
|
end
|
81
81
|
|
82
82
|
def cpu_mhz
|
@@ -103,7 +103,7 @@ module Kanrisuru
|
|
103
103
|
@cpu_architecture.flags
|
104
104
|
end
|
105
105
|
|
106
|
-
|
106
|
+
def hyperthreading?
|
107
107
|
threads_per_core > 1
|
108
108
|
end
|
109
109
|
|
data/lib/kanrisuru/remote/env.rb
CHANGED
data/lib/kanrisuru/version.rb
CHANGED
@@ -0,0 +1,194 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Apt do
|
6
|
+
before(:all) do
|
7
|
+
StubNetwork.stub!
|
8
|
+
StubNetwork.stub_command!(:realpath) do |args|
|
9
|
+
Kanrisuru::Core::Path::FilePath.new(directory)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
StubNetwork.unstub_command!(:realpath)
|
15
|
+
StubNetwork.unstub!
|
16
|
+
end
|
17
|
+
|
18
|
+
let(:host) do
|
19
|
+
Kanrisuru::Remote::Host.new(
|
20
|
+
host: 'localhost',
|
21
|
+
username: 'ubuntu',
|
22
|
+
keys: ['id_rsa']
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:directory) { '/home/ubuntu/dir' }
|
27
|
+
|
28
|
+
it 'prepares tar list command' do
|
29
|
+
['list', 't'].each do |action_variant|
|
30
|
+
expect_command(host.tar(action_variant, 'file.txt'),
|
31
|
+
'tar --restrict -f file.txt -t'
|
32
|
+
)
|
33
|
+
|
34
|
+
expect_command(host.tar(action_variant, '~/file.txt',
|
35
|
+
compress: 'bzip2',
|
36
|
+
directory: directory,
|
37
|
+
occurrence: 1,
|
38
|
+
label: true,
|
39
|
+
multi_volume: true
|
40
|
+
),
|
41
|
+
'tar --restrict -C /home/ubuntu/dir -f ~/file.txt -j -t --occurrence 1 --label --multi-volume'
|
42
|
+
)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'prepares tar extract command' do
|
47
|
+
['extract', 'get', 'x'].each do |action_variant|
|
48
|
+
expect_command(host.tar(action_variant, 'archive.tar'),
|
49
|
+
'tar --restrict -f archive.tar -x'
|
50
|
+
)
|
51
|
+
|
52
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
53
|
+
compress: 'xz',
|
54
|
+
directory: directory,
|
55
|
+
occurrence: 2,
|
56
|
+
no_same_owner: true,
|
57
|
+
no_same_permissions: true,
|
58
|
+
no_selinux: true,
|
59
|
+
no_xattrs: true,
|
60
|
+
multi_volume: true,
|
61
|
+
label: true,
|
62
|
+
skip_old_files: true,
|
63
|
+
overwrite: true,
|
64
|
+
overwrite_dir: true,
|
65
|
+
unlink_first: true,
|
66
|
+
recursive_unlink: true,
|
67
|
+
paths: 'file.txt'
|
68
|
+
),
|
69
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.tar -J -x --occurrence 2 --no-same-owner --no-same-permissions --no-selinux --no-xattrs --multi-volume --label --skip-old-files --overwrite --overwrite-dir --unlink-first --recursive-unlink file.txt'
|
70
|
+
)
|
71
|
+
|
72
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
73
|
+
preserve_permissions: true,
|
74
|
+
same_owners: true,
|
75
|
+
one_file_system: true,
|
76
|
+
keep_old_files: true,
|
77
|
+
paths: ['file1.txt', 'file2.txt']
|
78
|
+
),
|
79
|
+
'tar --restrict -f archive.tar -x --preserve-permissions --same-owner --one-file-system --keep-old-files file1.txt file2.txt'
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'prepares tar create command' do
|
85
|
+
['create', 'c'].each do |action_variant|
|
86
|
+
expect_command(host.tar(action_variant, 'archive.lzma', compress: 'lzma'), 'tar --restrict -f archive.lzma --lzma -c')
|
87
|
+
expect_command(host.tar(action_variant, 'archive.gz'), 'tar --restrict -f archive.gz -c')
|
88
|
+
|
89
|
+
expect_command(host.tar(action_variant, 'archive.gz',
|
90
|
+
directory: directory,
|
91
|
+
compress: 'gzip',
|
92
|
+
exclude: 'file2.txt',
|
93
|
+
paths: 'file1.txt'
|
94
|
+
),
|
95
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.gz -z -c --exclude=file2.txt file1.txt'
|
96
|
+
)
|
97
|
+
|
98
|
+
expect_command(host.tar(action_variant, 'archive.gz',
|
99
|
+
compress: 'gzip',
|
100
|
+
exclude: ['file2.txt', 'file4.txt'],
|
101
|
+
paths: ['file1.txt', 'file3.txt']
|
102
|
+
),
|
103
|
+
'tar --restrict -f archive.gz -z -c --exclude=file2.txt --exclude=file4.txt file1.txt file3.txt'
|
104
|
+
)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'prepares tar append command' do
|
109
|
+
['append', 'r'].each do |action_variant|
|
110
|
+
expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -r')
|
111
|
+
|
112
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
113
|
+
directory: directory,
|
114
|
+
paths: 'main.conf'
|
115
|
+
),
|
116
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.tar -r main.conf'
|
117
|
+
)
|
118
|
+
|
119
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
120
|
+
paths: ['main.conf', 'main2.conf']
|
121
|
+
),
|
122
|
+
'tar --restrict -f archive.tar -r main.conf main2.conf'
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'prepares tar concat command' do
|
128
|
+
['catenate', 'concat', 'A'].each do |action_variant|
|
129
|
+
expect_command(host.tar(action_variant, 'archive.tar'), 'tar --restrict -f archive.tar -A')
|
130
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
131
|
+
directory: directory,
|
132
|
+
paths: 'archive2.tar'
|
133
|
+
),
|
134
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar'
|
135
|
+
)
|
136
|
+
|
137
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
138
|
+
directory: directory,
|
139
|
+
paths: ['archive2.tar', 'archive3.tar']
|
140
|
+
),
|
141
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.tar -A archive2.tar archive3.tar'
|
142
|
+
)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'prepares tar update command' do
|
147
|
+
['update', 'u'].each do |action_variant|
|
148
|
+
expect_command(host.tar(action_variant, 'archive',
|
149
|
+
paths: 'file1.txt'
|
150
|
+
),
|
151
|
+
'tar --restrict -f archive -u file1.txt'
|
152
|
+
)
|
153
|
+
|
154
|
+
expect_command(host.tar(action_variant, 'archive',
|
155
|
+
directory: directory,
|
156
|
+
paths: ['file1.txt', 'file2.txt']
|
157
|
+
),
|
158
|
+
'tar --restrict -C /home/ubuntu/dir -f archive -u file1.txt file2.txt'
|
159
|
+
)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'prepares tar diff command' do
|
164
|
+
['diff', 'compare', 'd'].each do |action_variant|
|
165
|
+
expect_command(host.tar(action_variant, 'archive.tar', directory: directory), 'tar --restrict -C /home/ubuntu/dir -f archive.tar -d')
|
166
|
+
expect_command(host.tar(action_variant, 'archive.tar',
|
167
|
+
directory: directory,
|
168
|
+
occurrence: 4
|
169
|
+
),
|
170
|
+
'tar --restrict -C /home/ubuntu/dir -f archive.tar -d --occurrence 4'
|
171
|
+
)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'prepares tar delete command' do
|
176
|
+
expect_command(host.tar('delete', 'archive.tar', paths: 'file1.txt'), 'tar --restrict -f archive.tar --delete file1.txt')
|
177
|
+
expect_command(host.tar('delete', 'archive.tar',
|
178
|
+
paths: ['file1.txt', 'file2.txt'],
|
179
|
+
occurrence: 3
|
180
|
+
),
|
181
|
+
'tar --restrict -f archive.tar --delete --occurrence 3 file1.txt file2.txt'
|
182
|
+
)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'prepares invalid tar command' do
|
186
|
+
expect {
|
187
|
+
host.tar('abc', 'file1.txt')
|
188
|
+
}.to raise_error(ArgumentError)
|
189
|
+
|
190
|
+
expect {
|
191
|
+
host.tar('create', 'archive.tar', compress: 'xip')
|
192
|
+
}.to raise_error(ArgumentError)
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Remote::Cluster do
|
6
|
+
before(:all) do
|
7
|
+
StubNetwork.stub!
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
StubNetwork.unstub!
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:host1) do
|
15
|
+
Kanrisuru::Remote::Host.new(
|
16
|
+
host: 'localhost',
|
17
|
+
username: 'ubuntu',
|
18
|
+
keys: ['id_rsa']
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
let(:host2) do
|
23
|
+
Kanrisuru::Remote::Host.new(
|
24
|
+
host: 'ubuntu-host',
|
25
|
+
username: 'ubuntu',
|
26
|
+
keys: ['id_rsa']
|
27
|
+
)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'adds host to a cluster' do
|
31
|
+
cluster = Kanrisuru::Remote::Cluster.new(host1)
|
32
|
+
expect(cluster.hosts.length).to eq(1)
|
33
|
+
expect(cluster.count).to eq(1)
|
34
|
+
expect(cluster[host1.host]).to eq(host1)
|
35
|
+
expect(cluster.hosts).to include(host1)
|
36
|
+
|
37
|
+
cluster << host2
|
38
|
+
expect(cluster.hosts.length).to eq(2)
|
39
|
+
expect(cluster.count).to eq(2)
|
40
|
+
expect(cluster[host2.host]).to eq(host2)
|
41
|
+
expect(cluster.hosts).to include(host1)
|
42
|
+
expect(cluster.hosts).to include(host2)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'removes a host from a cluster' do
|
46
|
+
cluster = Kanrisuru::Remote::Cluster.new(host1, host2)
|
47
|
+
expect(cluster.count).to eq(2)
|
48
|
+
|
49
|
+
cluster.delete(host2)
|
50
|
+
expect(cluster.count).to eq(1)
|
51
|
+
expect(cluster.hosts).not_to include(host2)
|
52
|
+
|
53
|
+
cluster.delete(host1.host)
|
54
|
+
expect(cluster.count).to eq(0)
|
55
|
+
expect(cluster.hosts).not_to include(host1)
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Remote::Env do
|
6
|
+
|
7
|
+
let (:env) { Kanrisuru::Remote::Env.new }
|
8
|
+
|
9
|
+
it 'adds a environment variable' do
|
10
|
+
env['VAR1'] = 'hello'
|
11
|
+
expect(env.count).to eq(1)
|
12
|
+
expect(env.to_h).to eq({'VAR1' => 'hello'})
|
13
|
+
expect(env.to_s).to eq('export VAR1=hello;')
|
14
|
+
expect(env['VAR1']).to eq('hello')
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'adds multiple environment variables' do
|
18
|
+
env['var1'] = 'hello'
|
19
|
+
env['var2'] = 'world'
|
20
|
+
|
21
|
+
expect(env.count).to eq(2)
|
22
|
+
expect(env.to_h).to eq({'VAR1' => 'hello', 'VAR2' => 'world'})
|
23
|
+
expect(env.to_s).to eq('export VAR1=hello; export VAR2=world;')
|
24
|
+
expect(env['VAR1']).to eq('hello')
|
25
|
+
expect(env['VAR2']).to eq('world')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'deletes a variable' do
|
29
|
+
env[:var1] = 'foo'
|
30
|
+
expect(env.count).to eq(1)
|
31
|
+
expect(env[:var1]).to eq('foo')
|
32
|
+
env.delete(:var1)
|
33
|
+
expect(env.count).to eq(0)
|
34
|
+
expect(env.to_s).to eq('')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'clears the environment' do
|
38
|
+
env['VERSION'] = 1
|
39
|
+
env['SHELL'] = '/bin/zsh'
|
40
|
+
env['USER'] = 'ubuntu'
|
41
|
+
env['HOSTNAME'] = 'ubuntu'
|
42
|
+
expect(env.to_s).to eq('export VERSION=1; export SHELL=/bin/zsh; export USER=ubuntu; export HOSTNAME=ubuntu;')
|
43
|
+
|
44
|
+
expect(env.count).to eq(4)
|
45
|
+
env.clear
|
46
|
+
|
47
|
+
expect(env.count).to eq(0)
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/spec/helper/stub_network.rb
CHANGED
@@ -45,6 +45,22 @@ class StubNetwork
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
def stub_command!(method, &block)
|
49
|
+
Kanrisuru::Remote::Host.class_eval do
|
50
|
+
alias_method "#{method}_alias", method
|
51
|
+
|
52
|
+
define_method(method) do |*args|
|
53
|
+
block.call(args)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def unstub_command!(method)
|
59
|
+
Kanrisuru::Remote::Host.class_eval do
|
60
|
+
alias_method method, "#{method}_alias"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
48
64
|
def unstub!
|
49
65
|
Kanrisuru::Remote::Host.class_eval do
|
50
66
|
alias_method :execute_with_retries, :execute_with_retries_alias
|
@@ -82,10 +98,18 @@ class StubNetwork
|
|
82
98
|
processor: 'x86_64',
|
83
99
|
release: 'centos',
|
84
100
|
version: 7.0
|
101
|
+
},
|
102
|
+
opensuse: {
|
103
|
+
kernel_name: 'Linux',
|
104
|
+
kernel_version: '"#1 SMP Tue Jul 20 23:04:11 UTC 2021"',
|
105
|
+
operating_system: 'GNU/Linux',
|
106
|
+
hardware_platform: 'x86_64',
|
107
|
+
processor: 'x86_64',
|
108
|
+
release: 'opensuse-leap',
|
109
|
+
version:15.2
|
85
110
|
}
|
86
111
|
}
|
87
112
|
|
88
|
-
|
89
113
|
defaults[name].key?(property) ?
|
90
114
|
defaults[name][property] : nil
|
91
115
|
end
|
File without changes
|