kanrisuru 0.8.19 → 0.8.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 90fafd703817d1e16744262817dd0b5e5a51ea942f2853b154f4bd2746295fd7
4
- data.tar.gz: 0e0b35e325d3237faacbb71f22873b1c661495af0d93830e7ad91babbb060b3c
3
+ metadata.gz: cb7aac288555c629e9eb74721c2f0c21f45812426d4ac9b6e7fb1700433d360a
4
+ data.tar.gz: 16b5151fe50610ae0fe7ad4faa0eed72e49ad8aca017c7d6c609e377144c2532
5
5
  SHA512:
6
- metadata.gz: 76e116b83a5c119c0672b8ec5f1bac8f23307e1e06d3b393804df912f6110faf63527ca126ed4eb164d6ba58ef4ba92f3d1c3e15b252dc703058e39fc3ab4ba3
7
- data.tar.gz: 8e80e6457fd848d4dee5a31e33881c91458402df16cc82845b6300afc2543fe583fe48aeb2914e4329de9d9a668b6afbc2dd533d56886bd6fe0656ede58e5c95
6
+ metadata.gz: f4b592883b2f3541ae1ab7a4cbbf7ddaf626d376a39464401b428506eca21bf9546688384e0b8eb87e8f46c29a5c734356c4d407bb2f0aa47fe003d3e1e71a84
7
+ data.tar.gz: 0d8d36445c59ea52b7bbe25cfbc5782f21a42548fccdbcd3ae8f34431528b76a3a7bc13059583756c9fc4ce969b966479b632818dc2dc4dd23ef573a63c569e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## Kanrisuru 0.8.23 (November 19, 2021)
2
+ * Add functional test cases for `yum` command
3
+ * Add stub by operating system method, with support for `ubuntu` and `centos` os types.
4
+ * Fix `ArgumentError` typo in yum commands, `erase` and `remove`.
5
+
6
+ ## Kanrisuru 0.8.22 (November 18, 2021)
7
+ * Add functional test cases for `apt` command
8
+
9
+ ## Kanrisuru 0.8.21 (November 15, 2021)
10
+ * Fix bug with `Kanrisuru::Mode` class, lookup table had incorrect value for execute only symbolic to numeric field.
11
+
12
+ ## Kanrisuru 0.8.20 (November 13, 2021)
13
+ * Unstub network requests for full rspec test-suite run
14
+
1
15
  ## Kanrisuru 0.8.19 (October 31, 2021)
2
16
  * Add functional test cases for `ss` command.
3
17
  * Enforce contraints on `family` parameter for `ss` command.
@@ -137,7 +137,7 @@ module Kanrisuru
137
137
  command.append_flag('-y')
138
138
 
139
139
  packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
140
- raise ArugmentError, "can't remove yum" if packages.include?('yum')
140
+ raise ArgumentError, "can't remove yum" if packages.include?('yum')
141
141
 
142
142
  command << packages
143
143
 
@@ -173,7 +173,7 @@ module Kanrisuru
173
173
  command.append_flag('-y')
174
174
 
175
175
  packages = Kanrisuru::Util.array_join_string(opts[:packages], ' ')
176
- raise ArugmentError, "can't erase yum" if packages.include?('yum')
176
+ raise ArgumentError, "can't erase yum" if packages.include?('yum')
177
177
 
178
178
  command << packages
179
179
 
@@ -247,7 +247,7 @@ module Kanrisuru
247
247
  def symbolic_to_numeric(ref)
248
248
  conversions = {
249
249
  '---' => 0,
250
- '---x' => 1,
250
+ '--x' => 1,
251
251
  '-w-' => 2,
252
252
  '-wx' => 3,
253
253
  'r--' => 4,
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.19'
4
+ VERSION = '0.8.23'
5
5
  end
@@ -0,0 +1,96 @@
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
+ 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 apt list command' do
23
+ expect_command(host.apt('list'), 'apt list')
24
+ expect_command(host.apt('list',
25
+ installed: true,
26
+ upgradeable: true,
27
+ all_versions: true,
28
+ ), 'apt list --installed --upgradeable --all-versions')
29
+
30
+ expect_command(host.apt('list', package_name: 'nginx'), 'apt list -a nginx')
31
+ end
32
+
33
+ it 'prepares apt update command' do
34
+ expect_command(host.apt('update'), 'apt-get update -y')
35
+ end
36
+
37
+ it 'prepares apt upgrade command' do
38
+ expect_command(host.apt('upgrade'), 'apt-get upgrade -y')
39
+ end
40
+
41
+ it 'prepares apt full-upgrade command' do
42
+ expect_command(host.apt('full-upgrade'), 'apt full-upgrade -y')
43
+ end
44
+
45
+ it 'prepares apt install command' do
46
+ expect_command(host.apt('install',
47
+ packages: 'nginx'
48
+ ),
49
+ 'apt-get install -y nginx'
50
+ )
51
+
52
+ expect_command(host.apt('install',
53
+ packages: 'monit',
54
+ no_upgrade: true,
55
+ reinstall: true
56
+ ),
57
+ 'apt-get install -y --no-upgrade --reinstall monit'
58
+ )
59
+
60
+ expect_command(host.apt('install',
61
+ packages: ['build-essential', 'manpages-dev'],
62
+ only_upgrade: true,
63
+ ),
64
+ 'apt-get install -y --only-upgrade build-essential manpages-dev'
65
+ )
66
+ end
67
+
68
+ it 'prepares apt remove command' do
69
+ expect_command(host.apt('remove', packages: ['python']), 'apt-get remove -y python')
70
+ end
71
+
72
+ it 'prepares apt purge command' do
73
+ expect_command(host.apt('purge', packages: ['python']), 'apt-get purge -y python')
74
+ end
75
+
76
+ it 'prepares apt autoremove command' do
77
+ expect_command(host.apt('autoremove'), 'apt-get autoremove -y')
78
+ end
79
+
80
+ it 'prepares apt search command' do
81
+ expect_command(host.apt('search', query: 'ruby'), 'apt search ruby')
82
+ end
83
+
84
+ it 'prepares apt show command' do
85
+ expect_command(host.apt('show', packages: 'ruby'), 'apt show -a ruby')
86
+ end
87
+
88
+ it 'prepares apt clean command' do
89
+ expect_command(host.apt('clean'), 'apt-get clean')
90
+ end
91
+
92
+ it 'prepares apt autoclean command' do
93
+ expect_command(host.apt('autoclean'), 'apt-get autoclean')
94
+ end
95
+
96
+ end
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Find do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Path do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Socket do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Stat do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Stream do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -2,9 +2,15 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- StubNetwork.stub!
6
-
7
5
  RSpec.describe Kanrisuru::Core::Stat do
6
+ before(:all) do
7
+ StubNetwork.stub!
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
8
14
  let(:host) do
9
15
  Kanrisuru::Remote::Host.new(
10
16
  host: 'localhost',
@@ -0,0 +1,159 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Yum do
6
+ before(:all) do
7
+ StubNetwork.stub!(:centos)
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'centos-host',
17
+ username: 'centos',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'prepares yum install command' do
23
+ expect_command(host.yum('install', packages: 'nginx'),
24
+ 'yum install -y nginx'
25
+ )
26
+
27
+ expect_command(host.yum('install', packages: ['nginx', 'apache2']),
28
+ 'yum install -y nginx apache2'
29
+ )
30
+ end
31
+
32
+ it 'prepares yum localinstall command' do
33
+ expect_command(host.yum('localinstall', repos: 'foo.rpm'),
34
+ 'yum localinstall -y foo.rpm'
35
+ )
36
+
37
+ expect_command(host.yum('localinstall',
38
+ repos: ['foo.rpm', 'bar.rpm', 'baz.rpm'],
39
+ disable_repo: '*'
40
+ ),
41
+ 'yum localinstall --disablerepo=* -y foo.rpm bar.rpm baz.rpm'
42
+ )
43
+ end
44
+
45
+ it 'prepares yum list command' do
46
+ expect_command(host.yum('list'),
47
+ "yum list | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
48
+ )
49
+
50
+ expect_command(host.yum('list', all: true, query: 'ruby*'),
51
+ "yum list all ruby* | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
52
+ )
53
+
54
+ expect_command(host.yum('list',
55
+ available: true,
56
+ updates: true,
57
+ installed: true,
58
+ extras: true,
59
+ obsoletes: true,
60
+ disable_repo: '*'
61
+ ),
62
+ "yum list --disablerepo=* available updates installed extras obsoletes | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
63
+ )
64
+ end
65
+
66
+ it 'prepares yum search command' do
67
+ expect_command(host.yum('search',
68
+ packages: 'redis'
69
+ ),
70
+ "yum search redis | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
71
+ )
72
+
73
+ expect_command(host.yum('search',
74
+ packages: ['package1', 'package2', 'package3'],
75
+ all: true
76
+ ),
77
+ "yum search all package1 package2 package3 | tr '\\n' '#' | sed -e 's/# / /g' | tr '#' '\\n'"
78
+ )
79
+ end
80
+
81
+ it 'prepares yum info command' do
82
+ expect_command(host.yum('info',
83
+ packages: 'redis'
84
+ ),
85
+ "yum info --quiet redis"
86
+ )
87
+
88
+ expect_command(host.yum('info',
89
+ packages: ['package1', 'package2', 'package3'],
90
+ installed: true
91
+ ),
92
+ "yum info --quiet installed package1 package2 package3"
93
+ )
94
+ end
95
+
96
+ it 'prepares yum repolist command' do
97
+ expect_command(host.yum('repolist'),
98
+ "yum repolist --verbose"
99
+ )
100
+
101
+ expect_command(host.yum('repolist', repos: 'repo1'),
102
+ "yum repolist --verbose repo1"
103
+ )
104
+
105
+ expect_command(host.yum('repolist', repos: ['repo1', 'repo2', 'repo3']),
106
+ "yum repolist --verbose repo1 repo2 repo3"
107
+ )
108
+ end
109
+
110
+ it 'prepares yum clean command' do
111
+ expect_command(host.yum('clean'), 'yum clean')
112
+ expect_command(host.yum('clean', all: true), 'yum clean all')
113
+ expect_command(host.yum('clean',
114
+ dbcache: true,
115
+ expire_cache: true,
116
+ metadata: true,
117
+ packages: true,
118
+ headers: true,
119
+ rpmdb: true
120
+ ),
121
+ "yum clean dbcache expire-cache metadata packages headers rpmdb"
122
+ )
123
+ end
124
+
125
+ it 'prepares yum remove command' do
126
+ expect_command(host.yum('remove', packages: 'gcc'), 'yum remove -y gcc')
127
+ expect_command(host.yum('remove', packages: ['p1', 'p2', 'p3']),
128
+ 'yum remove -y p1 p2 p3'
129
+ )
130
+
131
+ expect {
132
+ host.yum('remove', packages: 'yum')
133
+ }.to raise_error(ArgumentError)
134
+ end
135
+
136
+ it 'prepares yum autoremove command' do
137
+ expect_command(host.yum('autoremove'), 'yum autoremove -y')
138
+ end
139
+
140
+ it 'prepares yum erase command' do
141
+ expect_command(host.yum('erase', packages: 'gcc'), 'yum erase -y gcc')
142
+ expect_command(host.yum('erase', packages: ['p1', 'p2', 'p3']),
143
+ 'yum erase -y p1 p2 p3'
144
+ )
145
+
146
+ expect {
147
+ host.yum('erase', packages: 'yum')
148
+ }.to raise_error(ArgumentError)
149
+ end
150
+
151
+ it 'prepares yum update command' do
152
+ expect_command(host.yum('update'), 'yum update -y')
153
+ end
154
+
155
+ it 'prepares yum upgrade command' do
156
+ expect_command(host.yum('upgrade'), 'yum upgrade -y')
157
+ end
158
+
159
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  def expect_command(result, string)
4
- puts result.command.raw_command
4
+ # puts result.command.raw_command
5
5
  expect(result.command.raw_command).to eq(
6
6
  string
7
7
  )
@@ -2,42 +2,93 @@
2
2
 
3
3
  class StubNetwork
4
4
  class << self
5
- def stub!
6
- ## Stub out the execute_with_retries method to
7
- ## test functionality of host commands
8
- Kanrisuru::Remote::Host.class_eval do
9
- private
10
-
11
- def execute_with_retries(command)
12
- command.handle_status(0)
13
- command.handle_data(nil)
5
+ def stub!(os_type = 'ubuntu')
6
+ unless Kanrisuru::Remote::Host.instance_methods(false).include?(:execute_with_retries_alias)
7
+ Kanrisuru::Remote::Host.class_eval do
8
+ alias_method :execute_with_retries_alias, :execute_with_retries
9
+ def execute_with_retries(command)
10
+ command.handle_status(0)
11
+ command.handle_data(nil)
14
12
 
15
- command
13
+ command
14
+ end
16
15
  end
17
16
  end
18
17
 
19
- Kanrisuru::Remote::Os.class_eval do
20
- def initialize(host)
21
- @host = host
22
-
23
- @kernel_name = 'Linux'
24
- @kernel_version = '#91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021'
25
- @operating_system = 'GNU/Linux'
26
- @hardware_platform = 'x86_64'
27
- @processor = 'x86_64'
28
- @release = 'ubuntu'
29
- @version = 20.0
18
+ unless Kanrisuru::Remote::Os.instance_methods(false).include?(:initialize_alias)
19
+ Kanrisuru::Remote::Os.class_eval do
20
+ alias_method :initialize_alias, :initialize
21
+ define_method :initialize do |host|
22
+ @host = host
23
+
24
+ @kernel_name = StubNetwork.send(:os_defaults, os_type, :kernel_name)
25
+ @kernel_version = StubNetwork.send(:os_defaults, os_type, :kernel_version)
26
+ @operating_system = StubNetwork.send(:os_defaults, os_type, :operating_system)
27
+ @hardware_platform = StubNetwork.send(:os_defaults, os_type, :hardware_platform)
28
+ @processor = StubNetwork.send(:os_defaults, os_type, :processor)
29
+ @release = StubNetwork.send(:os_defaults, os_type, :release)
30
+ @version = StubNetwork.send(:os_defaults, os_type, :version)
31
+ end
30
32
  end
31
33
  end
32
34
 
33
- Kanrisuru::Result.class_eval do
34
- def initialize(command)
35
- @command = command
36
- @data = nil
35
+ unless Kanrisuru::Result.instance_methods(false).include?(:initialize_alias)
36
+ Kanrisuru::Result.class_eval do
37
+ alias_method :initialize_alias, :initialize
38
+ def initialize(command)
39
+ @command = command
40
+ @data = nil
37
41
 
38
- @error = @command.to_a if @command.failure?
42
+ @error = @command.to_a if @command.failure?
43
+ end
39
44
  end
40
45
  end
41
46
  end
47
+
48
+ def unstub!
49
+ Kanrisuru::Remote::Host.class_eval do
50
+ alias_method :execute_with_retries, :execute_with_retries_alias
51
+ end
52
+
53
+ Kanrisuru::Remote::Os.class_eval do
54
+ alias_method :initialize, :initialize_alias
55
+ end
56
+
57
+ Kanrisuru::Result.class_eval do
58
+ alias_method :initialize, :initialize_alias
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def os_defaults(name, property)
65
+ name = name.to_sym
66
+
67
+ defaults = {
68
+ ubuntu: {
69
+ kernel_name: 'Linux',
70
+ kernel_version: '#91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021',
71
+ operating_system: 'GNU/Linux',
72
+ hardware_platform: 'x86_64',
73
+ processor: 'x86_64',
74
+ release: 'ubuntu',
75
+ version: 20.0
76
+ },
77
+ centos: {
78
+ kernel_name: 'Linux',
79
+ kernel_version: '"#1 SMP Wed Jul 21 11:57:15 UTC 2021"',
80
+ operating_system: 'GNU/Linux',
81
+ hardware_platform: 'x86_64',
82
+ processor: 'x86_64',
83
+ release: 'centos',
84
+ version: 7.0
85
+ }
86
+ }
87
+
88
+
89
+ defaults[name].key?(property) ?
90
+ defaults[name][property] : nil
91
+ end
92
+
42
93
  end
43
94
  end
@@ -79,6 +79,31 @@ RSpec.describe Kanrisuru::Mode do
79
79
  expect(mode.other.all?).to eq(true)
80
80
  expect(mode.other.to_i).to eq(7)
81
81
  expect(mode.other.symbolic).to eq('rwx')
82
+
83
+ mode = described_class.new("---x--x--x")
84
+ expect(mode.directory?).to eq(false)
85
+ expect(mode.numeric).to eq("111")
86
+
87
+ expect(mode.owner.read?).to eq(false)
88
+ expect(mode.owner.write?).to eq(false)
89
+ expect(mode.owner.execute?).to eq(true)
90
+ expect(mode.owner.all?).to eq(false)
91
+ expect(mode.owner.to_i).to eq(1)
92
+ expect(mode.owner.symbolic).to eq('--x')
93
+
94
+ expect(mode.group.read?).to eq(false)
95
+ expect(mode.group.write?).to eq(false)
96
+ expect(mode.group.execute?).to eq(true)
97
+ expect(mode.group.all?).to eq(false)
98
+ expect(mode.group.to_i).to eq(1)
99
+ expect(mode.group.symbolic).to eq('--x')
100
+
101
+ expect(mode.other.read?).to eq(false)
102
+ expect(mode.other.write?).to eq(false)
103
+ expect(mode.other.execute?).to eq(true)
104
+ expect(mode.other.all?).to eq(false)
105
+ expect(mode.other.to_i).to eq(1)
106
+ expect(mode.other.symbolic).to eq('--x')
82
107
  end
83
108
 
84
109
  it 'changes mode numerically globally' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kanrisuru
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.19
4
+ version: 0.8.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Mammina
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-31 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -173,12 +173,14 @@ files:
173
173
  - lib/kanrisuru/util/os_family.rb
174
174
  - lib/kanrisuru/util/signal.rb
175
175
  - lib/kanrisuru/version.rb
176
+ - spec/functional/core/apt_spec.rb
176
177
  - spec/functional/core/find_spec.rb
177
178
  - spec/functional/core/path_spec.rb
178
179
  - spec/functional/core/socket_spec.rb
179
180
  - spec/functional/core/stat_spec.rb
180
181
  - spec/functional/core/stream_spec.rb
181
182
  - spec/functional/core/transfer_spec.rb
183
+ - spec/functional/core/yum_spec.rb
182
184
  - spec/functional/os_package_spec.rb
183
185
  - spec/helper/expect_helpers.rb
184
186
  - spec/helper/stub_network.rb