kanrisuru 0.8.22 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 610fa46fc1f2af6ea5b805092f9528858c586cfad6c9754b18bdad109eaa9e77
4
- data.tar.gz: 210c27c89350d4b5cbbba4b5677711d2032f8d4bbbc7bac79a2c2a722f0c6caa
3
+ metadata.gz: 584b31f227df31d0a5e45ae8abd18a4a8f87f73622b78cf7a59b66878ac79d4b
4
+ data.tar.gz: c0917335ccd0955398574ad61756604e6f3516fd2e73958da733b711c16a152a
5
5
  SHA512:
6
- metadata.gz: cd1f29eb444fe67904563cc2f0edaf3480c068e374f75242f7d802d94588c7023549186ddce860f9ac1b79a66413435f18b57f36b3b53cfa5f688ca32689ba8f
7
- data.tar.gz: 3e784e517b5fa233c97b14dee47ab7f58562ebf2b484c602bd6d59ce1853a8749d7c53268574368269be7b4a711eac02bf6ce60bed1454232bf4d6a8a18b389d
6
+ metadata.gz: f950255db2459f0ead9452c026059723da0deca9e8688dc0efae3c11bf00f3ddc3787f246d99f3ab9cc3893b12915309d91ce2f35c3bd22b8c905a9f5d387387
7
+ data.tar.gz: 105d7d7193a037f357e14b31cc7af353a494810287b2dd557861077c27ec83cb64be3e64d2b9f49104438d0c5fe233d79374256c1a098bec8a50de335c3b20ba
data/.gitignore CHANGED
@@ -14,7 +14,6 @@
14
14
  .ruby-version
15
15
 
16
16
  *.gem
17
- coverage/*
18
17
  Gemfile.lock
19
18
  *~
20
19
  .bundle
@@ -26,3 +25,6 @@ pkg/*
26
25
  .env
27
26
  spec/dummy/tmp/*
28
27
  spec/dummy/log/*.log
28
+
29
+ coverage/*
30
+ codecov
data/CHANGELOG.md CHANGED
@@ -1,52 +1,70 @@
1
- ## Kanrisuru 0.8.22 (November 18, 2021)
1
+ ## Kanrisuru 0.9.2 (November 30, 2021) ##
2
+ * Add unit test cases for all core commands.
3
+ * Add unit test cases for `cluster` class.
4
+ * Add codecov xml output for coverage badge.
5
+
6
+ ## Kanrisuru 0.9.1 (November 29, 2021) ##
7
+ * Fix type on `address_sizes` for `Kanrisuru::Remote::Cpu` class.
8
+ * Add unit test cases for the `cpu` class.
9
+
10
+ ## Kanrisuru 0.9.0 (November 23, 2021) ##
11
+ * Add `delete` to `Kanrisuru::Remote::Cluster` class to allow removal of hosts from cluster.
12
+ * Add functional test cases for remote cluster class.
13
+
14
+ ## Kanrisuru 0.8.23 (November 19, 2021) ##
15
+ * Add functional test cases for `yum` command
16
+ * Add stub by operating system method, with support for `ubuntu` and `centos` os types.
17
+ * Fix `ArgumentError` typo in yum commands, `erase` and `remove`.
18
+
19
+ ## Kanrisuru 0.8.22 (November 18, 2021) ##
2
20
  * Add functional test cases for `apt` command
3
21
 
4
- ## Kanrisuru 0.8.21 (November 15, 2021)
22
+ ## Kanrisuru 0.8.21 (November 15, 2021) ##
5
23
  * Fix bug with `Kanrisuru::Mode` class, lookup table had incorrect value for execute only symbolic to numeric field.
6
24
 
7
- ## Kanrisuru 0.8.20 (November 13, 2021)
25
+ ## Kanrisuru 0.8.20 (November 13, 2021) ##
8
26
  * Unstub network requests for full rspec test-suite run
9
27
 
10
- ## Kanrisuru 0.8.19 (October 31, 2021)
28
+ ## Kanrisuru 0.8.19 (October 31, 2021) ##
11
29
  * Add functional test cases for `ss` command.
12
30
  * Enforce contraints on `family` parameter for `ss` command.
13
31
  * 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.
14
32
  * Replace `string_join_array` method calls in `apt`, `transfer`, `yum`, and `zypper` with `array_join_string`.
15
33
 
16
- ## Kanrisuru 0.8.18 (October 19, 2021)
34
+ ## Kanrisuru 0.8.18 (October 19, 2021) ##
17
35
  * Add functional test cases for `find` commmand.
18
36
  * Add `regex_type` option for `find` command.
19
37
  * 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.
20
38
 
21
- ## Kanrisuru 0.8.17 (October 16, 2021)
39
+ ## Kanrisuru 0.8.17 (October 16, 2021) ##
22
40
  * Add functional test cases for `transfer` module
23
41
  * Update wget command to accept hash for `headers` opt.
24
42
 
25
- ## Kanrisuru 0.8.16 (October 14, 2021)
43
+ ## Kanrisuru 0.8.16 (October 14, 2021) ##
26
44
  * Add functional test cases for `stream` and `path` modules
27
45
  * Create `expect_command` helper for quick testing on raw command result
28
46
 
29
- ## Kanrisuru 0.8.15 (October 12, 20201)
47
+ ## Kanrisuru 0.8.15 (October 12, 20201) ##
30
48
  * Move functional specs to integration. Anything that performs an actual network request will be under the integrations test.
31
49
  * 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.
32
50
  * Start with testing the `stat` command as a functional test.
33
51
 
34
- ## Kanrisuru 0.8.14 (October 8, 20201)
52
+ ## Kanrisuru 0.8.14 (October 8, 20201) ##
35
53
  * Update `Kanrisuru::Remote::Cluster` instantiation method to use array splat instead of passing array directly.
36
54
 
37
- ## Kanrisuru 0.8.13 (October 4, 20201)
55
+ ## Kanrisuru 0.8.13 (October 4, 20201) ##
38
56
  * Fix `wc` command. Ensure result parsing is cast to integer values.
39
57
 
40
- ## Kanrisuru 0.8.12 (October 4, 20201)
58
+ ## Kanrisuru 0.8.12 (October 4, 20201) ##
41
59
  * Refactor `rmdir` command to only work on empty directories.
42
60
 
43
- ## Kanrisuru 0.8.11 (October 1, 20201)
61
+ ## Kanrisuru 0.8.11 (October 1, 20201) ##
44
62
  * Allow `Kanrisuru::Mode` as mode type option in mkdir method.
45
63
 
46
- ## Kanrisuru 0.8.10 (August 24, 20201)
64
+ ## Kanrisuru 0.8.10 (August 24, 20201) ##
47
65
  * Fix bug with rspec test case.
48
66
 
49
- ## Kanrisuru 0.8.9 (August 24, 2021)
67
+ ## Kanrisuru 0.8.9 (August 24, 2021) ##
50
68
  * Fix spelling error exception `ArgumentError` in `Kanrisuru::Mode` class.
51
69
 
52
70
  ## Kanrisuru 0.8.8 (August 21, 2021) ##
@@ -116,7 +134,6 @@ cache key to avoid any namespace collisions with the same method name, namely:
116
134
  * Deprecating `cpu_info` with replacement of `lscpu`. `cpu_info` will be removed in the next major release.
117
135
 
118
136
  ## Kanrisuru 0.5.1 (July 29, 2021) ##
119
-
120
137
  * Unit test cases for core module structs, constants and types.
121
138
 
122
139
  ## Kanrisuru 0.5.0 (July 29, 2021) ##
@@ -153,15 +170,12 @@ cache key to avoid any namespace collisions with the same method name, namely:
153
170
  * Replace `cpu` module internal fetching of data from `cpu_info` to `lscpu` struct.
154
171
 
155
172
  ## Kanrisuru 0.2.9 (July 20, 2021) ##
156
-
157
173
  * Fix fstab entry from `entry` to `entry[:entry]` in the `for_each`iteration.
158
174
 
159
175
  ## Kanrisuru 0.2.8 (July 20, 2021) ##
160
-
161
176
  * Update gem development and runtime depedencies with stricter depencies.
162
177
 
163
178
  ## Kanrisuru 0.2.7 (July 18, 2021) ##
164
-
165
179
  * Set opensuse upstream to sles (Suse Enterprise Linux) in `os_family`
166
180
 
167
181
  ## 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 = 'Manage remote servers over ssh with ruby.'
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'
@@ -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
 
@@ -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 'Not a valid host option'
122
+ raise ArgumentError, 'Invalid host option'
91
123
  end
92
124
  end
93
125
  end
@@ -75,8 +75,8 @@ module Kanrisuru
75
75
  @cpu_architecture.byte_order
76
76
  end
77
77
 
78
- def address_size
79
- @cpu_architecture.address_size
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
- def hyperthreading?
106
+ def hyperthreading?
107
107
  threads_per_core > 1
108
108
  end
109
109
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.8.22'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -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
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  class StubNetwork
4
4
  class << self
5
- def stub!
5
+ def stub!(os_type = 'ubuntu')
6
6
  unless Kanrisuru::Remote::Host.instance_methods(false).include?(:execute_with_retries_alias)
7
7
  Kanrisuru::Remote::Host.class_eval do
8
8
  alias_method :execute_with_retries_alias, :execute_with_retries
@@ -18,16 +18,16 @@ class StubNetwork
18
18
  unless Kanrisuru::Remote::Os.instance_methods(false).include?(:initialize_alias)
19
19
  Kanrisuru::Remote::Os.class_eval do
20
20
  alias_method :initialize_alias, :initialize
21
- def initialize(host)
21
+ define_method :initialize do |host|
22
22
  @host = host
23
23
 
24
- @kernel_name = 'Linux'
25
- @kernel_version = '#91-Ubuntu SMP Thu Jul 15 19:09:17 UTC 2021'
26
- @operating_system = 'GNU/Linux'
27
- @hardware_platform = 'x86_64'
28
- @processor = 'x86_64'
29
- @release = 'ubuntu'
30
- @version = 20.0
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
31
  end
32
32
  end
33
33
  end
@@ -59,5 +59,44 @@ class StubNetwork
59
59
  end
60
60
  end
61
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
+ opensuse: {
87
+ kernel_name: 'Linux',
88
+ kernel_version: '"#1 SMP Tue Jul 20 23:04:11 UTC 2021"',
89
+ operating_system: 'GNU/Linux',
90
+ hardware_platform: 'x86_64',
91
+ processor: 'x86_64',
92
+ release: 'opensuse-leap',
93
+ version:15.2
94
+ }
95
+ }
96
+
97
+ defaults[name].key?(property) ?
98
+ defaults[name][property] : nil
99
+ end
100
+
62
101
  end
63
102
  end
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,9 @@
3
3
  require 'simplecov'
4
4
  SimpleCov.start
5
5
 
6
+ require 'simplecov-cobertura'
7
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
8
+
6
9
  require 'kanrisuru'
7
10
 
8
11
  require_relative 'helper/test_hosts'
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
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 'responds to methods' do
23
+ expect(host).to respond_to(:apt)
24
+ end
25
+
6
26
  it 'responds to apt fields' do
7
27
  expect(Kanrisuru::Core::Apt::Source.new).to respond_to(
8
28
  :url, :dist, :architecture
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Archive 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 'responds to methods' do
23
+ expect(host).to respond_to(:tar)
24
+ end
25
+
6
26
  it 'responds to archive fields' do
7
27
  expect(Kanrisuru::Core::Archive::FilePath.new).to respond_to(
8
28
  :path
@@ -3,6 +3,29 @@
3
3
  require 'spec_helper'
4
4
 
5
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 'responds to methods' do
23
+ expect(host).to respond_to(:df)
24
+ expect(host).to respond_to(:du)
25
+ expect(host).to respond_to(:blkid)
26
+ expect(host).to respond_to(:lsblk)
27
+ end
28
+
6
29
  it 'responds to disk fields' do
7
30
  expect(Kanrisuru::Core::Disk::DiskUsage.new).to respond_to(:fsize, :path)
8
31
  expect(Kanrisuru::Core::Disk::DiskFree.new).to respond_to(
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
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 'responds to methods' do
23
+ expect(host).to respond_to(:dmi)
24
+ end
25
+
6
26
  it 'responds to dmi type fields' do
7
27
  expect(Kanrisuru::Core::Dmi::BIOS.new).to respond_to(
8
28
  :dmi_type, :dmi_handle, :dmi_size,
@@ -3,6 +3,41 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::File 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 'responds to methods' do
23
+ expect(host).to respond_to(:touch)
24
+ expect(host).to respond_to(:cp)
25
+ expect(host).to respond_to(:copy)
26
+ expect(host).to respond_to(:mkdir)
27
+ expect(host).to respond_to(:mv)
28
+ expect(host).to respond_to(:move)
29
+ expect(host).to respond_to(:link)
30
+ expect(host).to respond_to(:symlink)
31
+ expect(host).to respond_to(:ln)
32
+ expect(host).to respond_to(:ln_s)
33
+ expect(host).to respond_to(:chmod)
34
+ expect(host).to respond_to(:chown)
35
+ expect(host).to respond_to(:unlink)
36
+ expect(host).to respond_to(:rm)
37
+ expect(host).to respond_to(:rmdir)
38
+ expect(host).to respond_to(:wc)
39
+ end
40
+
6
41
  it 'responds to file fields' do
7
42
  expect(Kanrisuru::Core::File::FileCount.new).to respond_to(:lines, :words, :characters)
8
43
  end
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
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
+
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 'responds to methods' do
23
+ expect(host).to respond_to(:find)
24
+ end
25
+
6
26
  it 'responds to find fields' do
7
27
  expect(Kanrisuru::Core::Find::FilePath.new).to respond_to(:path)
8
28
  expect(Kanrisuru::Core::Find::REGEX_TYPES).to(
@@ -3,6 +3,30 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Group 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 'responds to methods' do
23
+ expect(host).to respond_to(:group?)
24
+ expect(host).to respond_to(:get_gid)
25
+ expect(host).to respond_to(:create_group)
26
+ expect(host).to respond_to(:update_group)
27
+ expect(host).to respond_to(:delete_group)
28
+ end
29
+
6
30
  it 'responds to group fields' do
7
31
  expect(Kanrisuru::Core::Group::Group.new).to respond_to(:gid, :name, :users)
8
32
  expect(Kanrisuru::Core::Group::GroupUser.new).to respond_to(:uid, :name)
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::IP 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 'responds to methods' do
23
+ expect(host).to respond_to(:ip)
24
+ end
25
+
6
26
  it 'responds to ip fields' do
7
27
  expect(Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION).to(
8
28
  eq(180_129)
@@ -3,6 +3,31 @@
3
3
  require 'spec_helper'
4
4
 
5
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
+
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 'responds to methods' do
23
+ expect(host).to respond_to(:ls)
24
+ expect(host).to respond_to(:pwd)
25
+ expect(host).to respond_to(:realpath)
26
+ expect(host).to respond_to(:readlink)
27
+ expect(host).to respond_to(:whoami)
28
+ expect(host).to respond_to(:which)
29
+ end
30
+
6
31
  it 'responds to path fields' do
7
32
  expect(Kanrisuru::Core::Path::FilePath.new).to respond_to(:path)
8
33
  expect(Kanrisuru::Core::Path::FileInfoId.new).to respond_to(
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
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
+
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 'responds to methods' do
23
+ expect(host).to respond_to(:ss)
24
+ end
25
+
6
26
  it 'responds to socket fields' do
7
27
  expect(Kanrisuru::Core::Socket::Statistics.new).to respond_to(
8
28
  :netid, :state, :receive_queue, :send_queue,
@@ -3,6 +3,33 @@
3
3
  require 'spec_helper'
4
4
 
5
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
+
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 'responds to methods' do
23
+ expect(host).to respond_to(:dir?)
24
+ expect(host).to respond_to(:file?)
25
+ expect(host).to respond_to(:block_device?)
26
+ expect(host).to respond_to(:char_device?)
27
+ expect(host).to respond_to(:symlink?)
28
+ expect(host).to respond_to(:file_type?)
29
+ expect(host).to respond_to(:inode?)
30
+ expect(host).to respond_to(:stat)
31
+ end
32
+
6
33
  it 'responds to stat fields' do
7
34
  expect(Kanrisuru::Core::Stat::FileStat.new).to respond_to(
8
35
  :mode, :blocks, :device, :file_type,
@@ -3,6 +3,41 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::System 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 'responds to methods' do
23
+ expect(host).to respond_to(:load_env)
24
+ expect(host).to respond_to(:cpu_info)
25
+ expect(host).to respond_to(:lscpu)
26
+ expect(host).to respond_to(:load_average)
27
+ expect(host).to respond_to(:free)
28
+ expect(host).to respond_to(:ps)
29
+ expect(host).to respond_to(:kill)
30
+ expect(host).to respond_to(:kernel_statistics)
31
+ expect(host).to respond_to(:kstat)
32
+ expect(host).to respond_to(:lsof)
33
+ expect(host).to respond_to(:last)
34
+ expect(host).to respond_to(:uptime)
35
+ expect(host).to respond_to(:w)
36
+ expect(host).to respond_to(:who)
37
+ expect(host).to respond_to(:reboot)
38
+ expect(host).to respond_to(:poweroff)
39
+ end
40
+
6
41
  it 'responds to system fields' do
7
42
  expect(Kanrisuru::Core::System::CPUArchitectureVulnerability.new).to respond_to(
8
43
  :name,
@@ -3,6 +3,28 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Transfer 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 'responds to methods' do
23
+ expect(host).to respond_to(:download)
24
+ expect(host).to respond_to(:upload)
25
+ expect(host).to respond_to(:wget)
26
+ end
27
+
6
28
  it 'responds to transfer fields' do
7
29
  expect(Kanrisuru::Core::Transfer::WGET_FILENAME_MODES).to eq(
8
30
  %w[unix windows nocontrol ascii lowercase uppercase]
@@ -3,6 +3,31 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::User 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 'responds to methods' do
23
+ expect(host).to respond_to(:user?)
24
+ expect(host).to respond_to(:get_uid)
25
+ expect(host).to respond_to(:get_user)
26
+ expect(host).to respond_to(:create_user)
27
+ expect(host).to respond_to(:update_user)
28
+ expect(host).to respond_to(:delete_user)
29
+ end
30
+
6
31
  it 'responds to user fields' do
7
32
  expect(Kanrisuru::Core::User::User.new).to respond_to(:uid, :name, :home, :shell, :groups)
8
33
  expect(Kanrisuru::Core::User::UserGroup.new).to respond_to(:gid, :name)
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
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 'responds to methods' do
23
+ expect(host).to respond_to(:yum)
24
+ end
25
+
6
26
  it 'responds to yum fields' do
7
27
  expect(Kanrisuru::Core::Yum::PackageOverview.new).to respond_to(
8
28
  :package, :architecture, :version, :installed
@@ -3,6 +3,26 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  RSpec.describe Kanrisuru::Core::Zypper do
6
+ before(:all) do
7
+ StubNetwork.stub!('opensuse')
8
+ end
9
+
10
+ after(:all) do
11
+ StubNetwork.unstub!
12
+ end
13
+
14
+ let(:host) do
15
+ Kanrisuru::Remote::Host.new(
16
+ host: 'opensuse-host',
17
+ username: 'opensuse',
18
+ keys: ['id_rsa']
19
+ )
20
+ end
21
+
22
+ it 'responds to methods' do
23
+ expect(host).to respond_to(:zypper)
24
+ end
25
+
6
26
  it 'responds to zypper fields' do
7
27
  expect(Kanrisuru::Core::Zypper::PACKAGE_TYPES).to(
8
28
  eq(%w[package patch pattern product srcpackage application])
@@ -0,0 +1,34 @@
1
+ RSpec.describe Kanrisuru::Remote::Cluster do
2
+ before(:all) do
3
+ StubNetwork.stub!
4
+ end
5
+
6
+ after(:all) do
7
+ StubNetwork.unstub!
8
+ end
9
+
10
+ let(:host1) do
11
+ Kanrisuru::Remote::Host.new(
12
+ host: 'localhost',
13
+ username: 'ubuntu',
14
+ keys: ['id_rsa']
15
+ )
16
+ end
17
+
18
+ it 'responds to methods' do
19
+ cluster = Kanrisuru::Remote::Cluster.new(host1)
20
+ expect(cluster).to respond_to(:hosts)
21
+ expect(cluster).to respond_to(:[])
22
+ expect(cluster).to respond_to(:<<)
23
+ expect(cluster).to respond_to(:delete)
24
+ expect(cluster).to respond_to(:execute)
25
+ expect(cluster).to respond_to(:execute_shell)
26
+ expect(cluster).to respond_to(:each)
27
+ expect(cluster).to respond_to(:hostname)
28
+ expect(cluster).to respond_to(:ping?)
29
+ expect(cluster).to respond_to(:su)
30
+ expect(cluster).to respond_to(:chdir)
31
+ expect(cluster).to respond_to(:cd)
32
+ expect(cluster).to respond_to(:disconnect)
33
+ end
34
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Remote::Cpu 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 'responds to methods' do
23
+ cpu = Kanrisuru::Remote::Cpu.new(host)
24
+
25
+ expect(cpu).to respond_to(:load_average)
26
+ expect(cpu).to respond_to(:load_average1)
27
+ expect(cpu).to respond_to(:load_average5)
28
+ expect(cpu).to respond_to(:load_average15)
29
+ expect(cpu).to respond_to(:sockets)
30
+ expect(cpu).to respond_to(:cores)
31
+ expect(cpu).to respond_to(:total)
32
+ expect(cpu).to respond_to(:count)
33
+ expect(cpu).to respond_to(:threads_per_core)
34
+ expect(cpu).to respond_to(:cores_per_socket)
35
+ expect(cpu).to respond_to(:numa_nodes)
36
+ expect(cpu).to respond_to(:vendor_id)
37
+ expect(cpu).to respond_to(:cpu_family)
38
+ expect(cpu).to respond_to(:model)
39
+ expect(cpu).to respond_to(:model_name)
40
+ expect(cpu).to respond_to(:byte_order)
41
+ expect(cpu).to respond_to(:address_sizes)
42
+ expect(cpu).to respond_to(:cpu_mhz)
43
+ expect(cpu).to respond_to(:cpu_max_mhz)
44
+ expect(cpu).to respond_to(:cpu_min_mhz)
45
+ expect(cpu).to respond_to(:hypervisor)
46
+ expect(cpu).to respond_to(:virtualization_type)
47
+ expect(cpu).to respond_to(:flags)
48
+ expect(cpu).to respond_to(:hyperthreading?)
49
+ end
50
+ end
File without changes
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.22
4
+ version: 0.9.2
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-11-18 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-cobertura
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: net-ping
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -108,7 +122,8 @@ dependencies:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
124
  version: '6.1'
111
- description: Manage remote servers over ssh with ruby.
125
+ description: Kanrisuru helps manage remote servers with objected oriented ruby. Results
126
+ come back as structured data, parsed, prepared and ready .
112
127
  email: ryan@avamia.com
113
128
  executables: []
114
129
  extensions: []
@@ -180,7 +195,9 @@ files:
180
195
  - spec/functional/core/stat_spec.rb
181
196
  - spec/functional/core/stream_spec.rb
182
197
  - spec/functional/core/transfer_spec.rb
198
+ - spec/functional/core/yum_spec.rb
183
199
  - spec/functional/os_package_spec.rb
200
+ - spec/functional/remote/cluster_spec.rb
184
201
  - spec/helper/expect_helpers.rb
185
202
  - spec/helper/stub_network.rb
186
203
  - spec/helper/test_hosts.rb
@@ -227,9 +244,11 @@ files:
227
244
  - spec/unit/core/user_spec.rb
228
245
  - spec/unit/core/yum_spec.rb
229
246
  - spec/unit/core/zypper_spec.rb
230
- - spec/unit/fstab_spec.rb
231
247
  - spec/unit/kanrisuru_spec.rb
232
248
  - spec/unit/mode_spec.rb
249
+ - spec/unit/remote/cluster_spec.rb
250
+ - spec/unit/remote/cpu_spec.rb
251
+ - spec/unit/remote/fstab_spec.rb
233
252
  - spec/unit/template_spec.rb
234
253
  - spec/unit/util_spec.rb
235
254
  - spec/zz_reboot_spec.rb