kanrisuru 0.15.0 → 0.16.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +23 -0
- data/kanrisuru.gemspec +7 -3
- data/lib/kanrisuru/command.rb +6 -3
- data/lib/kanrisuru/core/disk/commands/lsblk.rb +6 -11
- data/lib/kanrisuru/core/disk/constants.rb +9 -0
- data/lib/kanrisuru/core/disk/parser.rb +1 -0
- data/lib/kanrisuru/core/disk/parsers/lsblk_version.rb +21 -0
- data/lib/kanrisuru/core/disk.rb +1 -0
- data/lib/kanrisuru/core/dmi/commands/dmi.rb +1 -1
- data/lib/kanrisuru/core/file/commands/chmod.rb +1 -1
- data/lib/kanrisuru/core/file/commands/copy.rb +1 -3
- data/lib/kanrisuru/core/file/commands/mkdir.rb +11 -6
- data/lib/kanrisuru/core/file/commands/rm.rb +4 -1
- data/lib/kanrisuru/core/file/commands/touch.rb +2 -1
- data/lib/kanrisuru/core/system/commands/kill.rb +1 -1
- data/lib/kanrisuru/core/user/commands/create_user.rb +9 -17
- data/lib/kanrisuru/core/user/commands/delete_user.rb +1 -1
- data/lib/kanrisuru/core/user/commands/update_user.rb +14 -23
- data/lib/kanrisuru/core/zypper/commands/add_repo.rb +1 -8
- data/lib/kanrisuru/core/zypper/commands/add_service.rb +4 -2
- data/lib/kanrisuru/core/zypper/commands/info.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/install.rb +2 -3
- data/lib/kanrisuru/core/zypper/commands/modify_repo.rb +1 -7
- data/lib/kanrisuru/core/zypper/commands/modify_service.rb +3 -1
- data/lib/kanrisuru/core/zypper/commands/remove.rb +1 -2
- data/lib/kanrisuru/core/zypper/commands/remove_repo.rb +3 -3
- data/lib/kanrisuru/core/zypper/commands/remove_service.rb +6 -1
- data/lib/kanrisuru/core/zypper/commands/search.rb +1 -3
- data/lib/kanrisuru/core/zypper/commands/source_install.rb +2 -0
- data/lib/kanrisuru/core/zypper/commands.rb +10 -1
- data/lib/kanrisuru/mode/permission.rb +103 -0
- data/lib/kanrisuru/mode.rb +2 -98
- data/lib/kanrisuru/os_package.rb +2 -0
- data/lib/kanrisuru/remote/host.rb +1 -3
- data/lib/kanrisuru/result.rb +15 -0
- data/lib/kanrisuru/version.rb +1 -1
- data/spec/functional/core/archive_spec.rb +1 -1
- data/spec/functional/core/disk_spec.rb +77 -0
- data/spec/functional/core/dmi_spec.rb +78 -0
- data/spec/functional/core/file_spec.rb +284 -0
- data/spec/functional/core/group_spec.rb +62 -0
- data/spec/functional/core/{ip/ip_address_label_spec.rb → ip_address_label_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_address_spec.rb → ip_address_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_link_spec.rb → ip_link_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_maddress_spec.rb → ip_maddress_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_neighbour_spec.rb → ip_neighbour_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_route_spec.rb → ip_route_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_rule_spec.rb → ip_rule_spec.rb} +0 -0
- data/spec/functional/core/{ip/ip_spec.rb → ip_spec.rb} +0 -0
- data/spec/functional/core/system_spec.rb +135 -0
- data/spec/functional/core/user_spec.rb +97 -0
- data/spec/functional/core/zypper_spec.rb +708 -0
- data/spec/functional/result_spec.rb +91 -44
- data/spec/helper/stub_network.rb +7 -3
- data/spec/unit/command_spec.rb +2 -0
- data/spec/unit/core/ip_spec.rb +12 -0
- metadata +23 -12
@@ -0,0 +1,103 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Kanrisuru
|
4
|
+
class Mode
|
5
|
+
class Permission
|
6
|
+
attr_reader :symbolic
|
7
|
+
|
8
|
+
def initialize(numeric, symbolic)
|
9
|
+
@numeric = numeric
|
10
|
+
@symbolic = symbolic
|
11
|
+
|
12
|
+
update_symbolic_rwx
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_i
|
16
|
+
numeric.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
symbolic
|
21
|
+
end
|
22
|
+
|
23
|
+
def numeric
|
24
|
+
@numeric.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
def all?
|
28
|
+
read? && write? && execute?
|
29
|
+
end
|
30
|
+
|
31
|
+
def symbolic=(symbolic)
|
32
|
+
@symbolic = symbolic
|
33
|
+
|
34
|
+
update_symbolic_rwx
|
35
|
+
update_numeric
|
36
|
+
end
|
37
|
+
|
38
|
+
def numeric=(numeric)
|
39
|
+
@numeric = numeric
|
40
|
+
|
41
|
+
update_numeric_rwx
|
42
|
+
update_symbolic
|
43
|
+
end
|
44
|
+
|
45
|
+
def read=(boolean)
|
46
|
+
@readable = boolean
|
47
|
+
|
48
|
+
update_numeric
|
49
|
+
update_symbolic
|
50
|
+
end
|
51
|
+
|
52
|
+
def write=(boolean)
|
53
|
+
@writeable = boolean
|
54
|
+
|
55
|
+
update_numeric
|
56
|
+
update_symbolic
|
57
|
+
end
|
58
|
+
|
59
|
+
def execute=(boolean)
|
60
|
+
@executable = boolean
|
61
|
+
|
62
|
+
update_numeric
|
63
|
+
update_symbolic
|
64
|
+
end
|
65
|
+
|
66
|
+
def read?
|
67
|
+
@readable
|
68
|
+
end
|
69
|
+
|
70
|
+
def write?
|
71
|
+
@writeable
|
72
|
+
end
|
73
|
+
|
74
|
+
def execute?
|
75
|
+
@executable
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def update_symbolic_rwx
|
81
|
+
@readable = @symbolic.include?('r')
|
82
|
+
@writeable = @symbolic.include?('w')
|
83
|
+
@executable = @symbolic.include?('x')
|
84
|
+
end
|
85
|
+
|
86
|
+
def update_numeric_rwx
|
87
|
+
mode = @numeric.to_i(8)
|
88
|
+
|
89
|
+
@readable = ((mode >> 2) & 0b001) == 1
|
90
|
+
@writeable = ((mode >> 1) & 0b001) == 1
|
91
|
+
@executable = ((mode >> 0) & 0b001) == 1
|
92
|
+
end
|
93
|
+
|
94
|
+
def update_numeric
|
95
|
+
@numeric = (((read? ? 1 : 0) << 2) + ((write? ? 1 : 0) << 1) + (execute? ? 1 : 0)).to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
def update_symbolic
|
99
|
+
@symbolic = "#{read? ? 'r' : '-'}#{write? ? 'w' : '-'}#{execute? ? 'x' : '-'}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
data/lib/kanrisuru/mode.rb
CHANGED
@@ -1,105 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'mode/permission'
|
4
|
+
|
3
5
|
module Kanrisuru
|
4
6
|
class Mode
|
5
|
-
class Permission
|
6
|
-
attr_reader :symbolic
|
7
|
-
|
8
|
-
def initialize(numeric, symbolic)
|
9
|
-
@numeric = numeric
|
10
|
-
@symbolic = symbolic
|
11
|
-
|
12
|
-
update_symbolic_rwx
|
13
|
-
end
|
14
|
-
|
15
|
-
def to_i
|
16
|
-
numeric.to_i
|
17
|
-
end
|
18
|
-
|
19
|
-
def to_s
|
20
|
-
symbolic
|
21
|
-
end
|
22
|
-
|
23
|
-
def numeric
|
24
|
-
@numeric.to_s
|
25
|
-
end
|
26
|
-
|
27
|
-
def all?
|
28
|
-
read? && write? && execute?
|
29
|
-
end
|
30
|
-
|
31
|
-
def symbolic=(symbolic)
|
32
|
-
@symbolic = symbolic
|
33
|
-
|
34
|
-
update_symbolic_rwx
|
35
|
-
update_numeric
|
36
|
-
end
|
37
|
-
|
38
|
-
def numeric=(numeric)
|
39
|
-
@numeric = numeric
|
40
|
-
|
41
|
-
update_numeric_rwx
|
42
|
-
update_symbolic
|
43
|
-
end
|
44
|
-
|
45
|
-
def read=(boolean)
|
46
|
-
@readable = boolean
|
47
|
-
|
48
|
-
update_numeric
|
49
|
-
update_symbolic
|
50
|
-
end
|
51
|
-
|
52
|
-
def write=(boolean)
|
53
|
-
@writeable = boolean
|
54
|
-
|
55
|
-
update_numeric
|
56
|
-
update_symbolic
|
57
|
-
end
|
58
|
-
|
59
|
-
def execute=(boolean)
|
60
|
-
@executable = boolean
|
61
|
-
|
62
|
-
update_numeric
|
63
|
-
update_symbolic
|
64
|
-
end
|
65
|
-
|
66
|
-
def read?
|
67
|
-
@readable
|
68
|
-
end
|
69
|
-
|
70
|
-
def write?
|
71
|
-
@writeable
|
72
|
-
end
|
73
|
-
|
74
|
-
def execute?
|
75
|
-
@executable
|
76
|
-
end
|
77
|
-
|
78
|
-
private
|
79
|
-
|
80
|
-
def update_symbolic_rwx
|
81
|
-
@readable = @symbolic.include?('r')
|
82
|
-
@writeable = @symbolic.include?('w')
|
83
|
-
@executable = @symbolic.include?('x')
|
84
|
-
end
|
85
|
-
|
86
|
-
def update_numeric_rwx
|
87
|
-
mode = @numeric.to_i(8)
|
88
|
-
|
89
|
-
@readable = ((mode >> 2) & 0b001) == 1
|
90
|
-
@writeable = ((mode >> 1) & 0b001) == 1
|
91
|
-
@executable = ((mode >> 0) & 0b001) == 1
|
92
|
-
end
|
93
|
-
|
94
|
-
def update_numeric
|
95
|
-
@numeric = (((read? ? 1 : 0) << 2) + ((write? ? 1 : 0) << 1) + (execute? ? 1 : 0)).to_s
|
96
|
-
end
|
97
|
-
|
98
|
-
def update_symbolic
|
99
|
-
@symbolic = "#{read? ? 'r' : '-'}#{write? ? 'w' : '-'}#{execute? ? 'x' : '-'}"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
7
|
attr_reader :owner, :group, :other
|
104
8
|
|
105
9
|
def initialize(mode)
|
data/lib/kanrisuru/os_package.rb
CHANGED
@@ -135,6 +135,7 @@ module Kanrisuru
|
|
135
135
|
end
|
136
136
|
|
137
137
|
ch.on_data do |_, data|
|
138
|
+
Kanrisuru.logger.debug { data.strip }
|
138
139
|
command.handle_data(data)
|
139
140
|
end
|
140
141
|
|
@@ -145,9 +146,6 @@ module Kanrisuru
|
|
145
146
|
end
|
146
147
|
|
147
148
|
channel.wait
|
148
|
-
|
149
|
-
Kanrisuru.logger.debug { command.to_a }
|
150
|
-
|
151
149
|
command
|
152
150
|
rescue Net::SSH::ConnectionTimeout, Net::SSH::Timeout => e
|
153
151
|
if retry_attempts > 1
|
data/lib/kanrisuru/result.rb
CHANGED
@@ -39,6 +39,21 @@ module Kanrisuru
|
|
39
39
|
@data.instance_of?(Array) ? @data : [@data]
|
40
40
|
end
|
41
41
|
|
42
|
+
def to_f
|
43
|
+
case @data
|
44
|
+
when Numeric
|
45
|
+
@data
|
46
|
+
when String
|
47
|
+
@data.to_f
|
48
|
+
when Array
|
49
|
+
@data.map(&:to_f)
|
50
|
+
when NilClass
|
51
|
+
nil
|
52
|
+
else
|
53
|
+
raise NoMethodError, "(undefined method `to_f' for Kanrisuru::Result)"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
42
57
|
def to_i
|
43
58
|
case @data
|
44
59
|
when Integer
|
data/lib/kanrisuru/version.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Disk do
|
6
|
+
before(:all) do
|
7
|
+
StubNetwork.stub!
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
StubNetwork.unstub!
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:host) do
|
15
|
+
Kanrisuru::Remote::Host.new(
|
16
|
+
host: 'localhost',
|
17
|
+
username: 'ubuntu',
|
18
|
+
keys: ['id_rsa']
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'prepares blkid command' do
|
23
|
+
expect_command(host.blkid, 'blkid -o export')
|
24
|
+
expect_command(host.blkid(device: '/dev/vda1'), 'blkid -pio export /dev/vda1')
|
25
|
+
expect_command(host.blkid(label: 'UEFI'), 'blkid -L UEFI')
|
26
|
+
expect_command(host.blkid(uuid: '26F2-56F9'), 'blkid -U 26F2-56F9')
|
27
|
+
expect_command(host.blkid(label: 'UEFI', uuid: '26F2-56F9'), 'blkid -L UEFI -U 26F2-56F9')
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'prepares df command' do
|
31
|
+
expect_command(host.df, "df -PT | awk '{print $1, $2, $3, $5, $6, $7}'")
|
32
|
+
expect_command(host.df(inodes: true, path: '/dev/vda1'),
|
33
|
+
"df -PT -i /dev/vda1 | awk '{print $1, $2, $3, $5, $6, $7}'")
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'prepares du command' do
|
37
|
+
expect_command(host.du, "du | awk '{print \\$1, \\$2}'")
|
38
|
+
expect_command(host.du(summarize: true, path: '/etc'), "du -s /etc | awk '{print \\$1, \\$2}'")
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'with json support' do
|
42
|
+
before(:all) do
|
43
|
+
StubNetwork.stub_command!(:lsblk_version) do
|
44
|
+
Kanrisuru::Core::Disk::LSBK_VERSION
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
StubNetwork.unstub_command!(:lsblk_version)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'prepares lsblk command' do
|
53
|
+
expect_command(host.lsblk, 'lsblk --json -o NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
|
54
|
+
expect_command(host.lsblk(all: true, paths: true, nodeps: true),
|
55
|
+
'lsblk --json -a -p -d -o NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'without json support' do
|
60
|
+
before(:all) do
|
61
|
+
StubNetwork.stub_command!(:lsblk_version) do
|
62
|
+
Kanrisuru::Core::Disk::LSBK_VERSION - 0.1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
after(:all) do
|
67
|
+
StubNetwork.unstub_command!(:lsblk_version)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'prepares lsblk command' do
|
71
|
+
expect_command(host.lsblk,
|
72
|
+
'lsblk -i -P --noheadings -o NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
|
73
|
+
expect_command(host.lsblk(all: true, paths: true, nodeps: true),
|
74
|
+
'lsblk -i -P --noheadings -a -p -d -o NAME,FSTYPE,MAJ:MIN,MOUNTPOINT,SIZE,UUID,RO,RM,OWNER,GROUP,MODE,TYPE')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
RSpec.describe Kanrisuru::Core::Dmi do
|
6
|
+
before(:all) do
|
7
|
+
StubNetwork.stub!
|
8
|
+
end
|
9
|
+
|
10
|
+
after(:all) do
|
11
|
+
StubNetwork.unstub!
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:host) do
|
15
|
+
Kanrisuru::Remote::Host.new(
|
16
|
+
host: 'localhost',
|
17
|
+
username: 'ubuntu',
|
18
|
+
keys: ['id_rsa']
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'prepares dmi command' do
|
23
|
+
expect_command(host.dmi, 'dmidecode')
|
24
|
+
expect_command(host.dmi(types: 'BIOS'), 'dmidecode --type 0')
|
25
|
+
expect_command(host.dmi(types: 1), 'dmidecode --type 1')
|
26
|
+
|
27
|
+
expect do
|
28
|
+
host.dmi(types: 'hello')
|
29
|
+
end.to raise_error(ArgumentError)
|
30
|
+
|
31
|
+
expect_command(host.dmi(types: [
|
32
|
+
'BIOS',
|
33
|
+
'System',
|
34
|
+
'Baseboard',
|
35
|
+
'Chassis',
|
36
|
+
'Processor',
|
37
|
+
'Memory Controller',
|
38
|
+
'Memory Module',
|
39
|
+
'Cache',
|
40
|
+
'Port Connector',
|
41
|
+
'System Slots',
|
42
|
+
'On Board Devices',
|
43
|
+
'OEM Strings',
|
44
|
+
'System Configuration Options',
|
45
|
+
'BIOS Language',
|
46
|
+
'Group Associations',
|
47
|
+
'System Event Log',
|
48
|
+
'Physical Memory Array',
|
49
|
+
'Memory Device',
|
50
|
+
'32-bit Memory Error',
|
51
|
+
'Memory Array Mapped Address',
|
52
|
+
'Memory Device Mapped Address',
|
53
|
+
'Built-in Pointing Device',
|
54
|
+
'Portable Battery',
|
55
|
+
'System Reset',
|
56
|
+
'Hardware Security',
|
57
|
+
'System Power Controls',
|
58
|
+
'Voltage Probe',
|
59
|
+
'Cooling Device',
|
60
|
+
'Temperature Probe',
|
61
|
+
'Electrical Current Probe',
|
62
|
+
'Out-of-band Remote Access',
|
63
|
+
'Boot Integrity Services',
|
64
|
+
'System Boot',
|
65
|
+
'64-bit Memory Error',
|
66
|
+
'Management Device',
|
67
|
+
'Management Device Component',
|
68
|
+
'Management Device Threshold Data',
|
69
|
+
'Memory Channel',
|
70
|
+
'IPMI Device',
|
71
|
+
'System Power Supply',
|
72
|
+
'Additional Information',
|
73
|
+
'Onboard Devices Extended Information',
|
74
|
+
'Management Controller Host Interface',
|
75
|
+
'TPM Device'
|
76
|
+
]), 'dmidecode --type 0 --type 1 --type 2 --type 3 --type 4 --type 5 --type 6 --type 7 --type 8 --type 9 --type 10 --type 11 --type 12 --type 13 --type 14 --type 15 --type 16 --type 17 --type 18 --type 19 --type 20 --type 21 --type 22 --type 23 --type 24 --type 25 --type 26 --type 27 --type 28 --type 29 --type 30 --type 31 --type 32 --type 33 --type 34 --type 35 --type 36 --type 37 --type 38 --type 39 --type 40 --type 41 --type 42 --type 43')
|
77
|
+
end
|
78
|
+
end
|