kanrisuru 0.1.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +17 -0
- data/.rubocop.yml +47 -0
- data/.rubocop_todo.yml +0 -0
- data/CHANGELOG.md +0 -0
- data/Gemfile +2 -5
- data/LICENSE.txt +1 -1
- data/README.md +143 -7
- data/Rakefile +5 -3
- data/bin/console +4 -3
- data/kanrisuru.gemspec +21 -12
- data/lib/kanrisuru.rb +41 -2
- data/lib/kanrisuru/command.rb +99 -0
- data/lib/kanrisuru/core.rb +53 -0
- data/lib/kanrisuru/core/archive.rb +154 -0
- data/lib/kanrisuru/core/disk.rb +302 -0
- data/lib/kanrisuru/core/file.rb +332 -0
- data/lib/kanrisuru/core/find.rb +108 -0
- data/lib/kanrisuru/core/group.rb +97 -0
- data/lib/kanrisuru/core/ip.rb +1032 -0
- data/lib/kanrisuru/core/mount.rb +138 -0
- data/lib/kanrisuru/core/path.rb +140 -0
- data/lib/kanrisuru/core/socket.rb +168 -0
- data/lib/kanrisuru/core/stat.rb +104 -0
- data/lib/kanrisuru/core/stream.rb +121 -0
- data/lib/kanrisuru/core/system.rb +348 -0
- data/lib/kanrisuru/core/transfer.rb +203 -0
- data/lib/kanrisuru/core/user.rb +198 -0
- data/lib/kanrisuru/logger.rb +8 -0
- data/lib/kanrisuru/mode.rb +277 -0
- data/lib/kanrisuru/os_package.rb +235 -0
- data/lib/kanrisuru/remote.rb +10 -0
- data/lib/kanrisuru/remote/cluster.rb +95 -0
- data/lib/kanrisuru/remote/cpu.rb +68 -0
- data/lib/kanrisuru/remote/env.rb +33 -0
- data/lib/kanrisuru/remote/file.rb +354 -0
- data/lib/kanrisuru/remote/fstab.rb +412 -0
- data/lib/kanrisuru/remote/host.rb +191 -0
- data/lib/kanrisuru/remote/memory.rb +19 -0
- data/lib/kanrisuru/remote/os.rb +87 -0
- data/lib/kanrisuru/result.rb +78 -0
- data/lib/kanrisuru/template.rb +32 -0
- data/lib/kanrisuru/util.rb +40 -0
- data/lib/kanrisuru/util/bits.rb +203 -0
- data/lib/kanrisuru/util/fs_mount_opts.rb +655 -0
- data/lib/kanrisuru/util/os_family.rb +213 -0
- data/lib/kanrisuru/util/signal.rb +161 -0
- data/lib/kanrisuru/version.rb +3 -1
- data/spec/functional/core/archive_spec.rb +228 -0
- data/spec/functional/core/disk_spec.rb +80 -0
- data/spec/functional/core/file_spec.rb +341 -0
- data/spec/functional/core/find_spec.rb +52 -0
- data/spec/functional/core/group_spec.rb +65 -0
- data/spec/functional/core/ip_spec.rb +71 -0
- data/spec/functional/core/path_spec.rb +93 -0
- data/spec/functional/core/socket_spec.rb +31 -0
- data/spec/functional/core/stat_spec.rb +98 -0
- data/spec/functional/core/stream_spec.rb +99 -0
- data/spec/functional/core/system_spec.rb +96 -0
- data/spec/functional/core/transfer_spec.rb +108 -0
- data/spec/functional/core/user_spec.rb +76 -0
- data/spec/functional/os_package_spec.rb +75 -0
- data/spec/functional/remote/cluster_spec.rb +45 -0
- data/spec/functional/remote/cpu_spec.rb +41 -0
- data/spec/functional/remote/env_spec.rb +36 -0
- data/spec/functional/remote/fstab_spec.rb +76 -0
- data/spec/functional/remote/host_spec.rb +68 -0
- data/spec/functional/remote/memory_spec.rb +29 -0
- data/spec/functional/remote/os_spec.rb +63 -0
- data/spec/functional/remote/remote_file_spec.rb +180 -0
- data/spec/helper/test_hosts.rb +68 -0
- data/spec/hosts.json +92 -0
- data/spec/spec_helper.rb +11 -3
- data/spec/unit/fstab_spec.rb +22 -0
- data/spec/unit/kanrisuru_spec.rb +9 -0
- data/spec/unit/mode_spec.rb +183 -0
- data/spec/unit/template_spec.rb +13 -0
- data/spec/unit/util_spec.rb +177 -0
- data/spec/zz_reboot_spec.rb +46 -0
- metadata +136 -13
- data/spec/kanrisuru_spec.rb +0 -9
@@ -0,0 +1,213 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
class Util
|
5
|
+
class OsFamily
|
6
|
+
@os_dict = {
|
7
|
+
unix: {
|
8
|
+
name: 'UNIX',
|
9
|
+
os_family: 'unix',
|
10
|
+
model: 'open_source',
|
11
|
+
type: 'abstract'
|
12
|
+
},
|
13
|
+
unix_like: {
|
14
|
+
name: 'unix-like',
|
15
|
+
os_family: 'unix',
|
16
|
+
type: 'abstract'
|
17
|
+
},
|
18
|
+
bsd: {
|
19
|
+
name: 'BSD',
|
20
|
+
os_family: 'unix',
|
21
|
+
upstream: 'unix',
|
22
|
+
model: 'open_source',
|
23
|
+
state: 'discontinued',
|
24
|
+
type: 'distribution'
|
25
|
+
},
|
26
|
+
solaris: {
|
27
|
+
name: 'Solaris',
|
28
|
+
os_family: 'unix',
|
29
|
+
upstream: 'bsd',
|
30
|
+
model: 'mixed',
|
31
|
+
state: 'current',
|
32
|
+
type: 'distribution'
|
33
|
+
},
|
34
|
+
free_bsd: {
|
35
|
+
name: 'FreeBSD',
|
36
|
+
os_family: 'unix_like',
|
37
|
+
upstream: 'bsd',
|
38
|
+
model: 'open_source',
|
39
|
+
state: 'current',
|
40
|
+
type: 'distribution'
|
41
|
+
},
|
42
|
+
dragon_fly_bsd: {
|
43
|
+
name: 'DragonFly BSD',
|
44
|
+
os_family: 'unix_like',
|
45
|
+
upstream: 'free_bsd',
|
46
|
+
model: 'open_source',
|
47
|
+
state: 'current',
|
48
|
+
type: 'distribution'
|
49
|
+
},
|
50
|
+
net_bsd: {
|
51
|
+
name: 'NetBSD',
|
52
|
+
os_family: 'unix_like',
|
53
|
+
upstream: 'bsd',
|
54
|
+
model: 'open_source',
|
55
|
+
state: 'current',
|
56
|
+
type: 'distribution'
|
57
|
+
},
|
58
|
+
open_bsd: {
|
59
|
+
name: 'OpenBSD',
|
60
|
+
os_family: 'unix_like',
|
61
|
+
upstream: 'net_bsd',
|
62
|
+
model: 'open_source',
|
63
|
+
state: 'current',
|
64
|
+
type: 'distribution'
|
65
|
+
},
|
66
|
+
darwin: {
|
67
|
+
name: 'Darwin',
|
68
|
+
os_family: 'unix_like',
|
69
|
+
upstream: 'free_bsd',
|
70
|
+
model: 'open_source',
|
71
|
+
state: 'current',
|
72
|
+
type: 'kernel'
|
73
|
+
},
|
74
|
+
pure_darwin: {
|
75
|
+
name: 'Pure Darwin',
|
76
|
+
os_family: 'darwin',
|
77
|
+
upstream: 'darwin',
|
78
|
+
model: 'open_source',
|
79
|
+
state: 'current',
|
80
|
+
type: 'distribution'
|
81
|
+
},
|
82
|
+
mac_os: {
|
83
|
+
name: 'MacOS',
|
84
|
+
os_family: 'darwin',
|
85
|
+
upstream: 'darwin',
|
86
|
+
model: 'closed_source',
|
87
|
+
state: 'current',
|
88
|
+
type: 'distribution'
|
89
|
+
},
|
90
|
+
mac: {
|
91
|
+
name: 'Mac',
|
92
|
+
type: 'alias',
|
93
|
+
to: 'mac_os'
|
94
|
+
},
|
95
|
+
mac_osx: {
|
96
|
+
name: 'MacOSX',
|
97
|
+
type: 'alias',
|
98
|
+
to: 'mac_os'
|
99
|
+
},
|
100
|
+
linux: {
|
101
|
+
name: 'GNU/Linux',
|
102
|
+
os_family: 'unix_like',
|
103
|
+
upstream: 'unix',
|
104
|
+
model: 'open_source',
|
105
|
+
state: 'current',
|
106
|
+
type: 'kernel'
|
107
|
+
},
|
108
|
+
debian: {
|
109
|
+
name: 'Debian',
|
110
|
+
os_family: 'linux',
|
111
|
+
upstream: 'linux',
|
112
|
+
model: 'open_source',
|
113
|
+
state: 'current',
|
114
|
+
type: 'distribution'
|
115
|
+
},
|
116
|
+
ubuntu: {
|
117
|
+
name: 'Ubuntu',
|
118
|
+
os_family: 'linux',
|
119
|
+
upstream: 'debian',
|
120
|
+
model: 'open_source',
|
121
|
+
state: 'current',
|
122
|
+
type: 'distribution'
|
123
|
+
},
|
124
|
+
linux_mint: {
|
125
|
+
name: 'Linux Mint',
|
126
|
+
os_family: 'linux',
|
127
|
+
upstream: 'ubuntu',
|
128
|
+
model: 'open_source',
|
129
|
+
state: 'current',
|
130
|
+
type: 'distribution'
|
131
|
+
},
|
132
|
+
fedora: {
|
133
|
+
name: 'Fedora',
|
134
|
+
os_family: 'linux',
|
135
|
+
upstream: 'linux',
|
136
|
+
model: 'open_source',
|
137
|
+
state: 'current',
|
138
|
+
type: 'distribution'
|
139
|
+
},
|
140
|
+
redhat: {
|
141
|
+
name: 'RHEL',
|
142
|
+
os_family: 'linux',
|
143
|
+
upstream: 'fedora',
|
144
|
+
model: 'commercial',
|
145
|
+
state: 'current',
|
146
|
+
type: 'distribution'
|
147
|
+
},
|
148
|
+
centos: {
|
149
|
+
name: 'CentOS',
|
150
|
+
type: 'alias',
|
151
|
+
to: 'cent_os'
|
152
|
+
},
|
153
|
+
cent_os: {
|
154
|
+
name: 'CentOS',
|
155
|
+
os_family: 'linux',
|
156
|
+
upstream: 'redhat',
|
157
|
+
model: 'open_source',
|
158
|
+
state: 'current',
|
159
|
+
type: 'distribution'
|
160
|
+
},
|
161
|
+
opensuse: {
|
162
|
+
name: 'openSUSE',
|
163
|
+
os_family: 'linux',
|
164
|
+
upstream: 'linux',
|
165
|
+
model: 'open_source',
|
166
|
+
state: 'current',
|
167
|
+
type: 'distribution'
|
168
|
+
},
|
169
|
+
opensuse_leap: {
|
170
|
+
name: 'openSUSE Leap',
|
171
|
+
type: 'alias',
|
172
|
+
to: 'opensuse'
|
173
|
+
},
|
174
|
+
sles: {
|
175
|
+
name: 'SUSE Linux Enterprise Server',
|
176
|
+
os_family: 'linux',
|
177
|
+
upstream: 'linux',
|
178
|
+
model: 'commercial',
|
179
|
+
state: 'current',
|
180
|
+
type: 'distribution'
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
def self.family_include_distribution?(family, dist)
|
185
|
+
if OsFamily[dist].nil?
|
186
|
+
false
|
187
|
+
elsif OsFamily[dist][:type] == 'alias'
|
188
|
+
family_include_distribution?(family, OsFamily[dist][:to])
|
189
|
+
elsif OsFamily[dist][:os_family] == family
|
190
|
+
true
|
191
|
+
else
|
192
|
+
family_include_distribution?(family, OsFamily[dist][:upstream])
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.upstream_include_distribution?(upstream, dist)
|
197
|
+
if OsFamily[dist].nil?
|
198
|
+
false
|
199
|
+
elsif OsFamily[dist][:type] == 'alias'
|
200
|
+
upstream_include_distribution?(upstream, OsFamily[dist][:to])
|
201
|
+
elsif OsFamily[dist][:upstream] == upstream && OsFamily[dist][:type] == 'distribution'
|
202
|
+
true
|
203
|
+
else
|
204
|
+
upstream_include_distribution?(upstream, OsFamily[dist][:upstream])
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.[](name)
|
209
|
+
@os_dict[name.to_sym] if !name.nil? && @os_dict.include?(name.to_sym)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
class Util
|
5
|
+
class Signal
|
6
|
+
@linux = {
|
7
|
+
'HUP' => 1,
|
8
|
+
'INT' => 2,
|
9
|
+
'QUIT' => 3,
|
10
|
+
'ILL' => 4,
|
11
|
+
'TRAP' => 5,
|
12
|
+
'ABRT' => 6,
|
13
|
+
'BUS' => 7,
|
14
|
+
'FPE' => 8,
|
15
|
+
'KILL' => 9,
|
16
|
+
'USR1' => 10,
|
17
|
+
'SEGV' => 11,
|
18
|
+
'USR2' => 12,
|
19
|
+
'PIPE' => 13,
|
20
|
+
'ALRM' => 14,
|
21
|
+
'TERM' => 15,
|
22
|
+
'STKFLT' => 16,
|
23
|
+
'CHLD' => 17,
|
24
|
+
'CONT' => 18,
|
25
|
+
'STOP' => 19,
|
26
|
+
'TSTP' => 20,
|
27
|
+
'TTIN' => 21,
|
28
|
+
'TTOU' => 22,
|
29
|
+
'URG' => 23,
|
30
|
+
'XCPU' => 24,
|
31
|
+
'XFSZ' => 25,
|
32
|
+
'VTALRM' => 26,
|
33
|
+
'PROF' => 27,
|
34
|
+
'WINCH' => 28,
|
35
|
+
'IO' => 29,
|
36
|
+
'PWR' => 30,
|
37
|
+
'SYS' => 31,
|
38
|
+
'RTMIN' => 34,
|
39
|
+
'RTMIN+1' => 35,
|
40
|
+
'RTMIN+2' => 36,
|
41
|
+
'RTMIN+3' => 37,
|
42
|
+
'RTMIN+4' => 38,
|
43
|
+
'RTMIN+5' => 39,
|
44
|
+
'RTMIN+6' => 40,
|
45
|
+
'RTMIN+7' => 41,
|
46
|
+
'RTMIN+8' => 42,
|
47
|
+
'RTMIN+9' => 43,
|
48
|
+
'RTMIN+10' => 44,
|
49
|
+
'RTMIN+11' => 45,
|
50
|
+
'RTMIN+12' => 46,
|
51
|
+
'RTMIN+13' => 47,
|
52
|
+
'RTMIN+14' => 48,
|
53
|
+
'RTMIN+15' => 49,
|
54
|
+
'RTMAX-14' => 50,
|
55
|
+
'RTMAX-13' => 51,
|
56
|
+
'RTMAX-12' => 52,
|
57
|
+
'RTMAX-11' => 53,
|
58
|
+
'RTMAX-10' => 54,
|
59
|
+
'RTMAX-9' => 55,
|
60
|
+
'RTMAX-8' => 56,
|
61
|
+
'RTMAX-7' => 57,
|
62
|
+
'RTMAX-6' => 58,
|
63
|
+
'RTMAX-5' => 59,
|
64
|
+
'RTMAX-4' => 60,
|
65
|
+
'RTMAX-3' => 61,
|
66
|
+
'RTMAX-2' => 62,
|
67
|
+
'RTMAX-1' => 63,
|
68
|
+
'RTMAX' => 64
|
69
|
+
}
|
70
|
+
|
71
|
+
@linux_inverted = {
|
72
|
+
1 => 'HUP',
|
73
|
+
2 => 'INT',
|
74
|
+
3 => 'QUIT',
|
75
|
+
4 => 'ILL',
|
76
|
+
5 => 'TRAP',
|
77
|
+
6 => 'ABRT',
|
78
|
+
7 => 'BUS',
|
79
|
+
8 => 'FPE',
|
80
|
+
9 => 'KILL',
|
81
|
+
10 => 'USR1',
|
82
|
+
11 => 'SEGV',
|
83
|
+
12 => 'USR2',
|
84
|
+
13 => 'PIPE',
|
85
|
+
14 => 'ALRM',
|
86
|
+
15 => 'TERM',
|
87
|
+
16 => 'STKFLT',
|
88
|
+
17 => 'CHLD',
|
89
|
+
18 => 'CONT',
|
90
|
+
19 => 'STOP',
|
91
|
+
20 => 'TSTP',
|
92
|
+
21 => 'TTIN',
|
93
|
+
22 => 'TTOU',
|
94
|
+
23 => 'URG',
|
95
|
+
24 => 'XCPU',
|
96
|
+
25 => 'XFSZ',
|
97
|
+
26 => 'VTALRM',
|
98
|
+
27 => 'PROF',
|
99
|
+
28 => 'WINCH',
|
100
|
+
29 => 'IO',
|
101
|
+
30 => 'PWR',
|
102
|
+
31 => 'SYS',
|
103
|
+
34 => 'RTMIN',
|
104
|
+
35 => 'RTMIN+1',
|
105
|
+
36 => 'RTMIN+2',
|
106
|
+
37 => 'RTMIN+3',
|
107
|
+
38 => 'RTMIN+4',
|
108
|
+
39 => 'RTMIN+5',
|
109
|
+
40 => 'RTMIN+6',
|
110
|
+
41 => 'RTMIN+7',
|
111
|
+
42 => 'RTMIN+8',
|
112
|
+
43 => 'RTMIN+9',
|
113
|
+
44 => 'RTMIN+10',
|
114
|
+
45 => 'RTMIN+11',
|
115
|
+
46 => 'RTMIN+12',
|
116
|
+
47 => 'RTMIN+13',
|
117
|
+
48 => 'RTMIN+14',
|
118
|
+
49 => 'RTMIN+15',
|
119
|
+
50 => 'RTMAX-14',
|
120
|
+
51 => 'RTMAX-13',
|
121
|
+
52 => 'RTMAX-12',
|
122
|
+
53 => 'RTMAX-11',
|
123
|
+
54 => 'RTMAX-10',
|
124
|
+
55 => 'RTMAX-9',
|
125
|
+
56 => 'RTMAX-8',
|
126
|
+
57 => 'RTMAX-7',
|
127
|
+
58 => 'RTMAX-6',
|
128
|
+
59 => 'RTMAX-5',
|
129
|
+
60 => 'RTMAX-4',
|
130
|
+
61 => 'RTMAX-3',
|
131
|
+
62 => 'RTMAX-2',
|
132
|
+
63 => 'RTMAX-1',
|
133
|
+
64 => 'RTMAX'
|
134
|
+
}
|
135
|
+
|
136
|
+
def self.[](signal)
|
137
|
+
return unless valid?(signal)
|
138
|
+
|
139
|
+
if key.instance_of?(Integer)
|
140
|
+
@linux_inverted[signal]
|
141
|
+
else
|
142
|
+
@linux[translate(signal)]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def self.valid?(signal)
|
147
|
+
if signal.instance_of?(Integer)
|
148
|
+
@linux_inverted.key?(signal)
|
149
|
+
elsif signal.instance_of?(String)
|
150
|
+
@linux.key?(translate(signal))
|
151
|
+
else
|
152
|
+
raise ArgumentError, 'Invalid data type'
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def self.translate(signal)
|
157
|
+
signal.gsub('SIG', '')
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -0,0 +1,228 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Archive do
|
6
|
+
TestHosts.each_os do |os_name|
|
7
|
+
context "with #{os_name}" do
|
8
|
+
before(:all) do
|
9
|
+
host_json = TestHosts.host(os_name)
|
10
|
+
host = Kanrisuru::Remote::Host.new(
|
11
|
+
host: host_json['hostname'],
|
12
|
+
username: host_json['username'],
|
13
|
+
keys: [host_json['ssh_key']]
|
14
|
+
)
|
15
|
+
|
16
|
+
host.mkdir("#{host_json['home']}/.kanrisuru_spec_files", silent: true)
|
17
|
+
host.disconnect
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:host_json) { TestHosts.host(os_name) }
|
21
|
+
let(:host) do
|
22
|
+
Kanrisuru::Remote::Host.new(
|
23
|
+
host: host_json['hostname'],
|
24
|
+
username: host_json['username'],
|
25
|
+
keys: [host_json['ssh_key']]
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:spec_dir) { "#{host_json['home']}/.kanrisuru_spec_files" }
|
30
|
+
|
31
|
+
after do
|
32
|
+
host.disconnect
|
33
|
+
end
|
34
|
+
|
35
|
+
after(:all) do
|
36
|
+
host_json = TestHosts.host(os_name)
|
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("#{host_json['home']}/.kanrisuru_spec_files")
|
44
|
+
host.rmdir("#{host_json['home']}/extract-tar-files") if host.dir?("#{host_json['home']}/extract-tar-files")
|
45
|
+
host.disconnect
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'tars an archive' do
|
49
|
+
archive = 'archive.tar'
|
50
|
+
archive2 = 'archive2.tar'
|
51
|
+
directory = spec_dir
|
52
|
+
|
53
|
+
host.touch("#{spec_dir}/test-file.txt")
|
54
|
+
host.touch("#{spec_dir}/test1.txt")
|
55
|
+
host.touch("#{spec_dir}/test2.txt")
|
56
|
+
host.touch("#{spec_dir}/test3.txt")
|
57
|
+
|
58
|
+
host.touch("#{spec_dir}/test1.config")
|
59
|
+
host.touch("#{spec_dir}/test2.config")
|
60
|
+
host.touch("#{spec_dir}/test3.config")
|
61
|
+
|
62
|
+
host.cd(spec_dir)
|
63
|
+
result = host.tar('create', archive, paths: ['*.txt'], exclude: 'test-file.txt', directory: directory)
|
64
|
+
|
65
|
+
expect(result.success?).to eq(true)
|
66
|
+
|
67
|
+
file = host.file("#{spec_dir}/#{archive}")
|
68
|
+
|
69
|
+
expect(file.path).to eq("#{spec_dir}/archive.tar")
|
70
|
+
expect(file.user).to eq(host_json['username'])
|
71
|
+
|
72
|
+
case os_name
|
73
|
+
when 'opensuse', 'sles'
|
74
|
+
expect(file.group).to eq('users')
|
75
|
+
else
|
76
|
+
expect(file.group).to eq(host_json['username'])
|
77
|
+
end
|
78
|
+
|
79
|
+
result = host.tar('list', archive, directory: directory)
|
80
|
+
expect(result.success?).to eq(true)
|
81
|
+
paths = result.map(&:path)
|
82
|
+
expect(paths.include?('test-file.txt')).to eq(false)
|
83
|
+
|
84
|
+
result = host.tar('append', archive, paths: 'test-file.txt', directory: directory)
|
85
|
+
expect(result.success?).to eq(true)
|
86
|
+
|
87
|
+
result = host.tar('list', archive, directory: directory)
|
88
|
+
paths = result.map(&:path)
|
89
|
+
|
90
|
+
expect(paths.include?('test-file.txt')).to eq(true)
|
91
|
+
|
92
|
+
result = host.tar('create', archive2, paths: '*.config', directory: directory)
|
93
|
+
expect(result.success?).to eq(true)
|
94
|
+
|
95
|
+
file = host.file("#{spec_dir}/#{archive2}")
|
96
|
+
|
97
|
+
expect(file.path).to eq("#{spec_dir}/archive2.tar")
|
98
|
+
expect(file.user).to eq(host_json['username'])
|
99
|
+
|
100
|
+
case os_name
|
101
|
+
when 'opensuse', 'sles'
|
102
|
+
expect(file.group).to eq('users')
|
103
|
+
else
|
104
|
+
expect(file.group).to eq(host_json['username'])
|
105
|
+
end
|
106
|
+
|
107
|
+
result = host.tar('concat', archive, paths: archive2, directory: directory)
|
108
|
+
expect(result.success?).to eq(true)
|
109
|
+
|
110
|
+
result = host.tar('list', archive, directory: directory)
|
111
|
+
expect(result.success?).to eq(true)
|
112
|
+
paths = result.map(&:path)
|
113
|
+
|
114
|
+
expect(paths.include?('test1.config')).to eq(true)
|
115
|
+
expect(paths.include?('test2.config')).to eq(true)
|
116
|
+
expect(paths.include?('test3.config')).to eq(true)
|
117
|
+
|
118
|
+
result = host.tar('diff', archive, directory: directory)
|
119
|
+
expect(result.success?).to eq(true)
|
120
|
+
|
121
|
+
result = host.tar('delete', archive, directory: directory, paths: 'test2.config')
|
122
|
+
expect(result.success?).to eq(true)
|
123
|
+
|
124
|
+
result = host.tar('list', archive, directory: directory)
|
125
|
+
expect(result.success?).to eq(true)
|
126
|
+
paths = result.map(&:path)
|
127
|
+
expect(paths.include?('test2.config')).to eq(false)
|
128
|
+
|
129
|
+
host.mkdir("#{host_json['home']}/extract-tar-files", silent: true)
|
130
|
+
host.tar('extract', 'archive.tar', directory: "#{host_json['home']}/extract-tar-files")
|
131
|
+
|
132
|
+
result = host.ls(path: "#{host_json['home']}/extract-tar-files")
|
133
|
+
paths = result.map(&:path)
|
134
|
+
|
135
|
+
expect(paths.include?('test1.config')).to eq(true)
|
136
|
+
expect(paths.include?('test3.config')).to eq(true)
|
137
|
+
expect(paths.include?('test-file.txt')).to eq(true)
|
138
|
+
expect(paths.include?('test1.txt')).to eq(true)
|
139
|
+
expect(paths.include?('test2.txt')).to eq(true)
|
140
|
+
expect(paths.include?('test3.txt')).to eq(true)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'compresses archive while tar' do
|
144
|
+
archive = 'archive.tar'
|
145
|
+
directory = spec_dir
|
146
|
+
|
147
|
+
host.touch("#{spec_dir}/test1.log")
|
148
|
+
host.touch("#{spec_dir}/test2.log")
|
149
|
+
host.touch("#{spec_dir}/test3.log")
|
150
|
+
|
151
|
+
host.cd(spec_dir)
|
152
|
+
result = host.tar('create', "#{archive}.gz", compress: 'gzip', paths: ['*.log'], directory: directory)
|
153
|
+
expect(result.success?).to eq(true)
|
154
|
+
|
155
|
+
file = host.file("#{spec_dir}/#{archive}.gz")
|
156
|
+
expect(file.path).to eq("#{spec_dir}/archive.tar.gz")
|
157
|
+
expect(file.uid).to eq(1000)
|
158
|
+
|
159
|
+
case os_name
|
160
|
+
when 'opensuse', 'sles'
|
161
|
+
expect(file.gid).to eq(100)
|
162
|
+
else
|
163
|
+
expect(file.gid).to eq(1000)
|
164
|
+
end
|
165
|
+
|
166
|
+
case os_name
|
167
|
+
when 'debian', 'ubuntu'
|
168
|
+
result = host.tar('create', "#{archive}.bz", compress: 'bzip2', paths: ['*.log'], directory: directory)
|
169
|
+
expect(result.success?).to eq(true)
|
170
|
+
|
171
|
+
file = host.file("#{spec_dir}/#{archive}.bz")
|
172
|
+
expect(file.path).to eq("#{spec_dir}/archive.tar.bz")
|
173
|
+
expect(file.uid).to eq(1000)
|
174
|
+
expect(file.gid).to eq(1000)
|
175
|
+
end
|
176
|
+
|
177
|
+
# case os_name
|
178
|
+
# when 'opensuse', 'sles'
|
179
|
+
# expect(file.gid).to eq(100)
|
180
|
+
# else
|
181
|
+
# end
|
182
|
+
|
183
|
+
case os_name
|
184
|
+
when 'debian'
|
185
|
+
## no op
|
186
|
+
else
|
187
|
+
result = host.tar('create', "#{archive}.xz", compress: 'xz', paths: ['*.log'], directory: directory)
|
188
|
+
expect(result.success?).to eq(true)
|
189
|
+
|
190
|
+
file = host.file("#{spec_dir}/#{archive}.xz")
|
191
|
+
expect(file.path).to eq("#{spec_dir}/archive.tar.xz")
|
192
|
+
expect(file.uid).to eq(1000)
|
193
|
+
|
194
|
+
case os_name
|
195
|
+
when 'opensuse', 'sles'
|
196
|
+
expect(file.gid).to eq(100)
|
197
|
+
else
|
198
|
+
expect(file.gid).to eq(1000)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
case os_name
|
203
|
+
when 'centos', 'rhel', 'debian'
|
204
|
+
## no op
|
205
|
+
else
|
206
|
+
result = host.tar('create', "#{archive}.lzma", compress: 'lzma', paths: ['*.log'], directory: directory)
|
207
|
+
expect(result.success?).to eq(true)
|
208
|
+
|
209
|
+
file = host.file("#{spec_dir}/#{archive}.lzma")
|
210
|
+
expect(file.path).to eq("#{spec_dir}/archive.tar.lzma")
|
211
|
+
expect(file.uid).to eq(1000)
|
212
|
+
|
213
|
+
case os_name
|
214
|
+
when 'opensuse', 'sles'
|
215
|
+
expect(file.gid).to eq(100)
|
216
|
+
else
|
217
|
+
expect(file.gid).to eq(1000)
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
expect do
|
222
|
+
host.tar('create', "#{archive}.lzop", compress: 'lzop', paths: ['*.log'],
|
223
|
+
directory: directory)
|
224
|
+
end.to raise_error(ArgumentError)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|