kanrisuru 0.5.0 → 0.7.0

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: 9e7d36fe867d1049287c11431cb348332d61b0a80e16163fa6a799fcc0fc26bb
4
- data.tar.gz: 0fef10f6eb28e176839f8b3a2995416fdb4c88fbfa8b4e24e2c36d719871237e
3
+ metadata.gz: bb8de477e2168c782b7cb082a6a6760fd56aa6925f1820ee80e45baff76a7b27
4
+ data.tar.gz: ad21e0b9787a2e42d8626a367f11b44ff97ec27f000a6ec8f7967d7b22da066d
5
5
  SHA512:
6
- metadata.gz: a96f6c7a0219c0ced7c87faa5923e2c8842dadd429787033885e89444af63943f41f7da88622224573d34940c8b5b3eb44c7fa324d20e146f9bae3e172c8b9b0
7
- data.tar.gz: c9cd28b4caf3daba48127d522a0f3f08ac925ee40c058320267cced2b0461b223378d314d48d248e2c614dca82533e12adba761c76e96b6bce976a3021700a5f
6
+ metadata.gz: 0cdeb2cda038612234429eb9ca172f294f60bb8bdcb0d5db2490231dfc4ab4205ae240b3f8ef8ebab41b5de6ef9d2599c7db76dd0ebe229b8b896e3a831c8805
7
+ data.tar.gz: b32d4fe02fe5897a8f56d827290516ceb393db63068f9cba3a4396b79e667dd62a332013fbb6fe674cd680ccd374faff877441f92f57048d5b782e244b23ec20
@@ -0,0 +1,17 @@
1
+ # How to contribute
2
+ Thank you for your interest in contributing to the Kanrisuru project. We appreciate any volunteers that want to help improve, grow and sustain the Kanrisuru code base!
3
+
4
+ ## Submitting a bug
5
+ * Do not open up a GitHub issue if the bug is a security vulnerability with the Kanrisuru project, instead send an email to engineeering@avamia.com for any security realted issues.
6
+ * Check if there's already an existing issue before submitting a [similar one](https://github.com/avamia/kanrisuru/issues).
7
+ * If you can't find a similar issue [open a new one](https://github.com/avamia/kanrisuru/issues/new?assignees=&labels=&template=bug_report.md). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
8
+
9
+ ## Adding a core feature
10
+ * We always welcome improving the core Kanrisuru project. If we are missing a core command available on most linux distros, this would be a place to add that type of functionality.
11
+ * Other ideas like performance optimization, additional testing, and ease of use are great ways of improving the project.
12
+ * If you want to create something outside of the core project, see the next section.
13
+
14
+ ## Adding a new module
15
+ * If you want to extent Kanrisuru beyond the underlying system code base or core module packages, the best way is to create a new gem, in the format of `kanrisuru-package`.
16
+ * This helps keep the core Kanrisuru package from too much bloat.
17
+ * See our developer module section to see how to build a new Kanrisuru module.
@@ -0,0 +1,33 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. Ubuntu]
28
+ - Version [e.g. 22]
29
+ - Ruby version: [e.g 2.7.4]
30
+
31
+
32
+ **Additional context**
33
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
data/.rubocop.yml CHANGED
@@ -20,6 +20,10 @@ Naming/InclusiveLanguage:
20
20
  - lib/kanrisuru/core/dmi.rb
21
21
  - spec/unit/core/dmi_spec.rb
22
22
 
23
+ Naming/MethodParameterName:
24
+ Exclude:
25
+ - spec/functional/os_package_spec.rb
26
+
23
27
  Metrics/AbcSize:
24
28
  Enabled: false
25
29
 
data/CHANGELOG.md CHANGED
@@ -0,0 +1,96 @@
1
+ ## Kanrisuru 0.7.0 (August 8, 2021) ##
2
+ * Simplify `FileInfo` struct for return object of `ls` command.
3
+ * Rename `size` to `fsize` for the `OpenFile` struct to avoid method naming conflicts of the struct class.
4
+ * Allow `os_include` and `os_collection` to define multiple groupings of methods with the same namespace.
5
+ * Add `clear` method for remote env class, to remove any session based env variables.
6
+ * Add `to_s` method to result for quick analysis of string based return values.
7
+ * Remove duplicate `numeric` method in the utils module.
8
+
9
+ ## Kanrisuru 0.6.0 (August 1, 2021) ##
10
+ * Add `lsof` implementation in system core module
11
+ * Fix changelog formatting
12
+ * Add changelog url to gemspec
13
+
14
+ ## Kanrisuru 0.5.2 (July 30, 2021) ##
15
+ * Add changelog documentation
16
+ * Update documentation table with new tested core module
17
+ * Deprecating `cpu_info` with replacement of `lscpu`. `cpu_info` will be removed in the next major release.
18
+
19
+ ## Kanrisuru 0.5.1 (July 29, 2021) ##
20
+
21
+ * Unit test cases for core module structs, constants and types.
22
+
23
+ ## Kanrisuru 0.5.0 (July 29, 2021) ##
24
+ * Add `zypper` package manager core module
25
+ * Add `dmi` core module. Support for getting hardware information from virtual and physical machines.
26
+ * Add only options for test_hosts to filter on which hosts to use for function style test cases. This is used within a test case and takes priority over command line `HOSTS=` and `EXCLUDE=` env variables.
27
+ * Add additional bit conversion string handling in the util module, such as kib, mib, and gib.
28
+ * Remove redudant namespacing in struct names, such as
29
+ `Kanrisuru::Core::Yum::YumPackageOverview`, to `Kanrisuru::Core::Yum::PackageOverview`.
30
+ * Fix backups test case for `cp` command with the correct filename.
31
+ * Use 0755 as expected numeric mode for all OS functional tests in the `mkdir` test case.
32
+ * Fix bug with `lscpu` regex match on cpus with more than 9 cores, ie `/cpu\d/` to `/cpu\d+/`
33
+
34
+
35
+ ## Kanrisuru 0.4.1 (July 26, 2021) ##
36
+ * Add `kernel_statistics` to system core module.
37
+
38
+ ## Kanrisuru 0.4.0 (July 25, 2021) ##
39
+ * Update internal exit code of command from 0, to array of accpeted exit codes, with 0 being the default value.
40
+ * Add `append_exit_code` to command, allowing additional exit codes to be considered true for `success?` return value.
41
+ * Add `@port` to `Net::SSH.start` method
42
+ * Fix test case with `host.os` return value of `opensuse_leap`.
43
+ * Add `cpu_flags` method to `cpu` module
44
+
45
+ ## Kanrisuru 0.3.2 (July 23, 2021) ##
46
+ * Fix typo from `key` to `signal` in hash fetch method.
47
+
48
+ ## Kanrisuru 0.3.1 (July 22, 2021) ##
49
+ * Add additional methods to `cpu` pulling from `lscpu` struct.
50
+ * Fix `address_size` in `cpu` method call.
51
+
52
+ ## Kanrisuru 0.3.0 (July 22, 2021) ##
53
+ * Add `lscpu` system core module
54
+ * Replace `cpu` module internal fetching of data from `cpu_info` to `lscpu` struct.
55
+
56
+ ## Kanrisuru 0.2.9 (July 20, 2021) ##
57
+
58
+ * Fix fstab entry from `entry` to `entry[:entry]` in the `for_each`iteration.
59
+
60
+ ## Kanrisuru 0.2.8 (July 20, 2021) ##
61
+
62
+ * Update gem development and runtime depedencies with stricter depencies.
63
+
64
+ ## Kanrisuru 0.2.7 (July 18, 2021) ##
65
+
66
+ * Set opensuse upstream to sles (Suse Enterprise Linux) in `os_family`
67
+
68
+ ## Kanrisuru 0.2.6 (July 17, 2021) ##
69
+ * Force "-" to "\_" from `os-release` release name in `host.os` module.
70
+
71
+ ## Kanrisuru 0.2.5 (July 16, 2021) ##
72
+ * Update gem depedencies to non-zero values
73
+ * Change summary and description fields for `apt`
74
+ * Move `normalize_size` from `apt` core module, to
75
+ `Kanrisuru::Util::Bits` class.
76
+ * Add additional test cases for `apt` core module.
77
+ * Add `-hi` to `who` command to explicility print out ip address for user.
78
+ * Update `inode?` command to execute without shell user.
79
+ * Add `yum` package manager core module
80
+
81
+ ## Kanrisuru 0.2.4 (July 10, 2021) ##
82
+ * Fix error in `ip_rule` and `ip_address` sub modules with command typo.
83
+
84
+ ## Kanrisuru 0.2.3 (July 07, 2021) ##
85
+ * Add `apt` package manager core module
86
+
87
+ ## Kanrisuru 0.2.2 (June 16, 2021) ##
88
+ * Fix `read_file_chunk` on checking bounds for start and end line values.
89
+
90
+ ## Kanrisuru 0.2.1 (June 16, 2021) ##
91
+ * Add first working release on rubygems.org
92
+
93
+ ## Kanrisuru 0.2.0 (June 16, 2021) [YANKED] ##
94
+
95
+ ## Kanrisuru 0.1.0 (December 12, 2020) ##
96
+ * Initialize repository, start working on project.
data/README.md CHANGED
@@ -2,6 +2,10 @@
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
4
 
5
+ <p align='center'>
6
+ <img src="https://s3.us-east-2.amazonaws.com/kanrisuru.com/kanrisuru-banner-02.png" width="600" />
7
+ </p>
8
+
5
9
  # Kanrisuru
6
10
 
7
11
  Kanrisuru (manage) helps you remotely control infrastructure using Ruby. This is done over SSH. I'm working on building up some basic functionality to help quickly provision, deploy and manage a single host or cluster of hosts.
@@ -79,6 +83,10 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
79
83
  |---------------------------------------|------------------|--------------------|--------|--------------------------------------|--------|--------|--------|--------|------|----------|------|
80
84
  | **System** | | | | | | | | | | | |
81
85
  | Get CPU Info | cpu_info | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
86
+ | Get CPU architecture | lscpu | lscpu | core | https://linux.die.net/man/1/lscpu | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
87
+ | Get kernel stastics | kernel_statistics | cat /proc/stat | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
88
+ | Get hardware BIOS info | dmi | dmidecode | core | https://linux.die.net/man/8/dmidecode | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
89
+ | Get open file details for processes | lsof | lsof | core | https://linux.die.net/man/8/lsof | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
82
90
  | Get Load Average | load_average | cat /proc/load_avg | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
83
91
  | Get RAM Available | free | cat /proc/meminfo | core | | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
84
92
  | Get list of processes | ps | ps | core | https://linux.die.net/man/1/ps | [x] | [x] | [x] | [x] | [x] | [x] | [x] |
@@ -149,6 +157,7 @@ cluster.execute('uname') #=> {host: 'host1', result: 'Linux'}, {host: 'host2', r
149
157
  | **Packages** | | | | | | | | | | | |
150
158
  | Apt | apt | apt | core | https://linux.die.net/man/1/apt | [x] | [x] | | | | | |
151
159
  | Yum | yum | yum | core | https://linux.die.net/man/1/yum | | | [x] | [x] | [x] | | |
160
+ | Zypper | zypper | zypper | core | https://en.opensuse.org/SDB:Zypper_manual | | | | | | [x] | [x] |
152
161
 
153
162
  ## Development
154
163
 
data/kanrisuru.gemspec CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |gem|
27
27
  gem.require_paths = ['lib']
28
28
 
29
29
  gem.metadata = {
30
- 'source_code_uri' => 'https://github.com/avamia/kanrisuru/'
30
+ 'source_code_uri' => 'https://github.com/avamia/kanrisuru/',
31
+ 'changelog_uri' => 'https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md'
31
32
  }
32
33
  end
@@ -9,10 +9,10 @@ module Kanrisuru
9
9
 
10
10
  os_define :linux, :ls
11
11
  os_define :linux, :pwd
12
- os_define :linux, :whoami
13
- os_define :linux, :which
14
12
  os_define :linux, :realpath
15
13
  os_define :linux, :readlink
14
+ os_define :linux, :whoami
15
+ os_define :linux, :which
16
16
 
17
17
  FilePath = Struct.new(:path)
18
18
  FileInfoId = Struct.new(:inode, :mode, :memory_blocks, :uid, :gid, :fsize, :date, :path, :type)
@@ -46,7 +46,7 @@ module Kanrisuru
46
46
  type = values[1].include?('d') ? 'directory' : 'file'
47
47
  items <<
48
48
  if id
49
- FileInfoId.new(
49
+ FileInfo.new(
50
50
  values[0].to_i,
51
51
  Kanrisuru::Mode.new(values[1]),
52
52
  values[2].to_i,
@@ -16,6 +16,9 @@ module Kanrisuru
16
16
  os_define :linux, :kill
17
17
 
18
18
  os_define :linux, :kernel_statistics
19
+ os_define :linux, :kstat
20
+
21
+ os_define :linux, :lsof
19
22
 
20
23
  os_define :linux, :uptime
21
24
 
@@ -101,6 +104,18 @@ module Kanrisuru
101
104
 
102
105
  UserLoggedIn = Struct.new(:user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command)
103
106
 
107
+ OpenFile = Struct.new(
108
+ :command,
109
+ :pid,
110
+ :uid,
111
+ :file_descriptor,
112
+ :type,
113
+ :device,
114
+ :fsize,
115
+ :inode,
116
+ :name
117
+ )
118
+
104
119
  def load_env
105
120
  command = Kanrisuru::Command.new('env')
106
121
  execute_shell(command)
@@ -205,6 +220,10 @@ module Kanrisuru
205
220
  end
206
221
 
207
222
  def cpu_info(spec)
223
+ Kanrisuru.logger.info do
224
+ 'DEPRECATION WARNING: cpu_info will be removed in the upcoming major release. Use lscpu instead.'
225
+ end
226
+
208
227
  name =
209
228
  case spec
210
229
  when 'sockets'
@@ -301,6 +320,60 @@ module Kanrisuru
301
320
  Kanrisuru::Result.new(command)
302
321
  end
303
322
 
323
+ def lsof(_opts = {})
324
+ command = Kanrisuru::Command.new('lsof -F pcuftDsin')
325
+
326
+ execute_shell(command)
327
+ Kanrisuru::Result.new(command) do |cmd|
328
+ lines = cmd.to_a
329
+
330
+ current_row = nil
331
+ current_pid = nil
332
+ current_user = nil
333
+ current_command = nil
334
+
335
+ rows = []
336
+
337
+ lines.each do |line|
338
+ case line
339
+ when /^p/
340
+ current_pid = parse_lsof(line, 'p').to_i
341
+ when /^c/
342
+ current_command = parse_lsof(line, 'c')
343
+ when /^u/
344
+ current_user = parse_lsof(line, 'u').to_i
345
+ when /^f/
346
+ rows << current_row if current_row
347
+
348
+ current_row = OpenFile.new
349
+ current_row.pid = current_pid
350
+ current_row.command = current_command
351
+ current_row.uid = current_user
352
+
353
+ current_row.file_descriptor = parse_lsof(line, 'f')
354
+ when /^t/
355
+ current_row.type = parse_lsof(line, 't')
356
+ when /^D/
357
+ current_row.device = parse_lsof(line, 'D')
358
+ when /^s/
359
+ current_row.fsize = parse_lsof(line, 's').to_i
360
+ when /^i/
361
+ current_row.inode = parse_lsof(line, 'i').to_i
362
+ when /^n/
363
+ current_row.name = parse_lsof(line, 'n')
364
+ end
365
+ end
366
+
367
+ rows << current_row if current_row
368
+
369
+ rows
370
+ end
371
+ end
372
+
373
+ def kstat
374
+ kernel_statistics
375
+ end
376
+
304
377
  def kernel_statistics
305
378
  command = Kanrisuru::Command.new('cat /proc/stat')
306
379
 
@@ -490,6 +563,10 @@ module Kanrisuru
490
563
 
491
564
  private
492
565
 
566
+ def parse_lsof(line, char)
567
+ line.split(char, 2)[1]
568
+ end
569
+
493
570
  def parse_policy_abbr(value)
494
571
  case value
495
572
  when '-'
@@ -46,13 +46,19 @@ module Kanrisuru
46
46
  ## Define the namespace as an eigen class instance on the host.
47
47
  ## Namespaced instances will access core host methods
48
48
  ## with @host instance variable.
49
- namespace_class = Kanrisuru::Remote::Cluster.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
50
- namespace_instance = Kanrisuru::Remote::Cluster.instance_variable_set("@#{namespace}", namespace_class.new)
51
49
 
52
- class_eval do
53
- define_method namespace do
54
- namespace_instance.instance_variable_set(:@cluster, self)
55
- namespace_instance
50
+ if Kanrisuru::Remote::Cluster.instance_variable_defined?("@#{namespace}")
51
+ namespace_class = Kanrisuru::Remote::Cluster.const_get(Kanrisuru::Util.camelize(namespace))
52
+ namespace_instance = instance_variable_get("@#{namespace}")
53
+ else
54
+ namespace_class = Kanrisuru::Remote::Cluster.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
55
+ namespace_instance = Kanrisuru::Remote::Cluster.instance_variable_set("@#{namespace}", namespace_class.new)
56
+
57
+ class_eval do
58
+ define_method namespace do
59
+ namespace_instance.instance_variable_set(:@cluster, self)
60
+ namespace_instance
61
+ end
56
62
  end
57
63
  end
58
64
 
@@ -132,17 +138,25 @@ module Kanrisuru
132
138
  ## Define the namespace as an eigen class instance within the host class.
133
139
  ## Namespaced instances will access core host methods
134
140
  ## with @host instance variable.
135
- namespace_class = Kanrisuru::Remote::Host.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
136
- namespace_instance = Kanrisuru::Remote::Host.instance_variable_set("@#{namespace}", namespace_class.new)
137
-
138
- namespace_class.class_eval(&include_method_bindings)
139
141
 
140
- class_eval do
141
- define_method namespace do
142
- namespace_instance.instance_variable_set(:@host, self)
143
- namespace_instance
142
+ ## Check to see if the namespace was defined. If so, additional methods will be appended to the
143
+ ## existing namespace class definition, otherwise, a new namespace class and instance will be
144
+ ## defined with the methods added.
145
+ if Kanrisuru::Remote::Host.instance_variable_defined?("@#{namespace}")
146
+ namespace_class = Kanrisuru::Remote::Host.const_get(Kanrisuru::Util.camelize(namespace))
147
+ namespace_instance = instance_variable_get("@#{namespace}")
148
+ else
149
+ namespace_class = Kanrisuru::Remote::Host.const_set(Kanrisuru::Util.camelize(namespace), Class.new)
150
+ namespace_instance = Kanrisuru::Remote::Host.instance_variable_set("@#{namespace}", namespace_class.new)
151
+ class_eval do
152
+ define_method namespace do
153
+ namespace_instance.instance_variable_set(:@host, self)
154
+ namespace_instance
155
+ end
144
156
  end
145
157
  end
158
+
159
+ namespace_class.class_eval(&include_method_bindings)
146
160
  else
147
161
  class_eval(&include_method_bindings)
148
162
  end
@@ -11,6 +11,10 @@ module Kanrisuru
11
11
  @env
12
12
  end
13
13
 
14
+ def clear
15
+ @env = {}
16
+ end
17
+
14
18
  def to_s
15
19
  string = ''
16
20
  @env.each.with_index do |(key, value), index|
@@ -31,6 +31,10 @@ module Kanrisuru
31
31
  @data[prop]
32
32
  end
33
33
 
34
+ def to_s
35
+ @data.to_s
36
+ end
37
+
34
38
  def to_a
35
39
  @data.instance_of?(Array) ? @data : [@data]
36
40
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kanrisuru
4
- VERSION = '0.5.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -26,14 +26,20 @@ RSpec.describe Kanrisuru::Core::System do
26
26
 
27
27
  it 'gets environment variables' do
28
28
  result = host.load_env
29
-
30
- expect(result.success?).to be(true)
29
+ expect(result).to be_success
31
30
  expect(result.data).to be_instance_of(Hash)
32
31
  end
33
32
 
33
+ it 'gets open files' do
34
+ host.su('root')
35
+ result = host.lsof
36
+ expect(result).to be_success
37
+ expect(result.data).to be_instance_of(Array)
38
+ end
39
+
34
40
  it 'gets uptime' do
35
41
  result = host.uptime
36
- expect(result.success?).to eq(true)
42
+ expect(result).to be_success
37
43
 
38
44
  expect(result).to respond_to(
39
45
  :boot_time, :uptime, :seconds,
@@ -16,7 +16,7 @@ module Kanrisuru
16
16
  module TestNamespace
17
17
  extend Kanrisuru::OsPackage::Define
18
18
 
19
- os_define :unix_like, :tester
19
+ os_define :linux, :tester
20
20
  os_define :centos, :test_not_correct
21
21
 
22
22
  def tester
@@ -25,17 +25,34 @@ module Kanrisuru
25
25
 
26
26
  def test_not_correct; end
27
27
  end
28
+
29
+ module TestNamespaceAdditions
30
+ extend Kanrisuru::OsPackage::Define
31
+
32
+ os_define :linux, :add
33
+ os_define :linux, :minus
34
+
35
+ def add(a, b)
36
+ a + b
37
+ end
38
+
39
+ def minus(a, b)
40
+ a - b
41
+ end
42
+ end
28
43
  end
29
44
 
30
45
  module Kanrisuru
31
46
  module Remote
32
47
  class Host
33
48
  os_include Kanrisuru::TestInclude
49
+ os_include Kanrisuru::TestNamespaceAdditions, namespace: :asdf
34
50
  os_include Kanrisuru::TestNamespace, namespace: :asdf
35
51
  end
36
52
 
37
53
  class Cluster
38
54
  os_collection Kanrisuru::TestInclude
55
+ os_collection Kanrisuru::TestNamespaceAdditions, namespace: :asdf
39
56
  os_collection Kanrisuru::TestNamespace, namespace: :asdf
40
57
  end
41
58
  end
@@ -64,8 +81,15 @@ RSpec.describe Kanrisuru::OsPackage do
64
81
 
65
82
  expect(host).to respond_to(:asdf)
66
83
  expect(host.asdf).to respond_to(:tester)
84
+ expect(host.asdf).to respond_to(:add)
85
+ expect(host.asdf).to respond_to(:minus)
86
+
67
87
  expect(host.asdf.tester).to eq 'hello namespace'
88
+ expect(host.asdf.add(1, 2)).to eq(3)
89
+ expect(host.asdf.minus(3, 2)).to eq(1)
90
+
68
91
  expect(host.tester).to eq('hello ubuntu')
92
+
69
93
  expect { host.asdf.test_not_correct }.to raise_error(NoMethodError)
70
94
  expect(cluster.asdf.tester).to be_instance_of(Array)
71
95
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Apt do
6
+ it 'responds to apt fields' do
7
+ expect(Kanrisuru::Core::Apt::Source.new).to respond_to(
8
+ :url, :dist, :architecture
9
+ )
10
+
11
+ expect(Kanrisuru::Core::Apt::PackageOverview.new).to respond_to(
12
+ :package, :version, :suites, :architecture, :installed, :upgradeable, :automatic
13
+ )
14
+
15
+ expect(Kanrisuru::Core::Apt::PackageDetail.new).to respond_to(
16
+ :package,
17
+ :version,
18
+ :priority,
19
+ :section,
20
+ :origin,
21
+ :maintainer,
22
+ :original_maintainer,
23
+ :bugs,
24
+ :install_size,
25
+ :dependencies,
26
+ :recommends,
27
+ :provides,
28
+ :suggests,
29
+ :breaks,
30
+ :conflicts,
31
+ :replaces,
32
+ :homepage,
33
+ :task,
34
+ :supported,
35
+ :download_size,
36
+ :apt_manual_installed,
37
+ :apt_sources,
38
+ :description,
39
+ :summary
40
+ )
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Archive do
6
+ it 'responds to archive fields' do
7
+ expect(Kanrisuru::Core::Archive::FilePath.new).to respond_to(
8
+ :path
9
+ )
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Disk do
6
+ it 'responds to disk fields' do
7
+ expect(Kanrisuru::Core::Disk::DiskUsage.new).to respond_to(:fsize, :path)
8
+ expect(Kanrisuru::Core::Disk::DiskFree.new).to respond_to(
9
+ :file_system, :type, :total, :used, :capacity, :mount
10
+ )
11
+ expect(Kanrisuru::Core::Disk::LsblkDevice.new).to respond_to(
12
+ :name, :maj_dev, :min_dev, :removable_device, :readonly_device, :owner, :group,
13
+ :mode, :fsize, :type, :mount_point, :fs_type, :uuid, :children
14
+ )
15
+ expect(Kanrisuru::Core::Disk::BlkidDevice.new).to respond_to(
16
+ :name, :label, :uuid, :type, :uuid_sub, :label_fatboot, :version, :usage,
17
+ :part_uuid, :part_entry_scheme, :part_entry_uuid, :part_entry_type,
18
+ :part_entry_number, :part_entry_offset, :part_entry_size, :part_entry_disk
19
+ )
20
+ end
21
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::File do
6
+ it 'responds to file fields' do
7
+ expect(Kanrisuru::Core::File::FileCount.new).to respond_to(:lines, :words, :characters)
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Find do
6
+ it 'responds to find fields' do
7
+ expect(Kanrisuru::Core::Find::FilePath.new).to respond_to(:path)
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Group do
6
+ it 'responds to group fields' do
7
+ expect(Kanrisuru::Core::Group::Group.new).to respond_to(:gid, :name, :users)
8
+ expect(Kanrisuru::Core::Group::GroupUser.new).to respond_to(:uid, :name)
9
+ end
10
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::IP do
6
+ it 'responds to ip fields' do
7
+ expect(Kanrisuru::Core::IP::IPROUTE2_JSON_VERSION).to(
8
+ eq(180_129)
9
+ )
10
+
11
+ expect(Kanrisuru::Core::IP::IP_ROUTE_TYPES).to(
12
+ eq(%w[
13
+ unicast unreachable blackhole prohibit local
14
+ broadcast throw nat via anycast multicast
15
+ ])
16
+ )
17
+
18
+ expect(Kanrisuru::Core::IP::IPLinkProperty.new).to respond_to(
19
+ :index, :name, :flags, :mtu,
20
+ :qdisc, :state, :group, :qlen,
21
+ :link_mode, :link_type, :mac_address, :alias,
22
+ :stats
23
+ )
24
+ expect(Kanrisuru::Core::IP::IPAddressProperty.new).to respond_to(
25
+ :index, :name, :flags, :mtu,
26
+ :qdisc, :state, :group, :qlen,
27
+ :link_type, :mac_address,
28
+ :address_info, :stats
29
+ )
30
+ expect(Kanrisuru::Core::IP::IPAddressInfo.new).to respond_to(
31
+ :family, :ip, :broadcast, :scope,
32
+ :dynamic, :valid_life_time, :preferred_life_time
33
+ )
34
+ expect(Kanrisuru::Core::IP::IPAddressLabel.new).to respond_to(
35
+ :address, :prefix_length, :label
36
+ )
37
+ expect(Kanrisuru::Core::IP::IPRoute.new).to respond_to(
38
+ :destination, :gateway, :device, :protocol, :scope, :preferred_source, :metric, :flags
39
+ )
40
+ expect(Kanrisuru::Core::IP::IPRule.new).to respond_to(:priority, :source, :table)
41
+ expect(Kanrisuru::Core::IP::IPNeighbour.new).to respond_to(
42
+ :destination, :device, :lladdr, :state, :stats
43
+ )
44
+ expect(Kanrisuru::Core::IP::IPNeighbourStats.new).to respond_to(
45
+ :used, :confirmed, :updated, :probes, :ref_count
46
+ )
47
+ expect(Kanrisuru::Core::IP::IPMAddress.new).to respond_to(:index, :name, :maddr)
48
+ expect(Kanrisuru::Core::IP::IPMAddressEntry.new).to respond_to(
49
+ :family, :link, :address, :users
50
+ )
51
+ expect(Kanrisuru::Core::IP::IPStats.new).to respond_to(:rx, :tx)
52
+ expect(Kanrisuru::Core::IP::IPStatRX.new).to respond_to(
53
+ :bytes, :packets, :errors, :dropped, :over_errors, :multicast
54
+ )
55
+ expect(Kanrisuru::Core::IP::IPStatTX.new).to respond_to(
56
+ :bytes, :packets, :errors, :dropped, :carrier_errors, :collisions
57
+ )
58
+ end
59
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Path do
6
+ it 'responds to path fields' do
7
+ expect(Kanrisuru::Core::Path::FilePath.new).to respond_to(:path)
8
+ expect(Kanrisuru::Core::Path::FileInfoId.new).to respond_to(
9
+ :inode, :mode, :memory_blocks, :uid, :gid, :fsize, :date, :path, :type
10
+ )
11
+ expect(Kanrisuru::Core::Path::FileInfo.new).to respond_to(
12
+ :inode, :mode, :memory_blocks, :owner, :group, :fsize, :date, :path, :type
13
+ )
14
+ expect(Kanrisuru::Core::Path::UserName.new).to respond_to(:user)
15
+ end
16
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Socket do
6
+ it 'responds to socket fields' do
7
+ expect(Kanrisuru::Core::Socket::Statistics.new).to respond_to(
8
+ :netid, :state, :receive_queue, :send_queue,
9
+ :local_address, :local_port, :peer_address, :peer_port,
10
+ :memory
11
+ )
12
+ expect(Kanrisuru::Core::Socket::StatisticsMemory.new).to respond_to(
13
+ :rmem_alloc, :rcv_buf, :wmem_alloc, :snd_buf,
14
+ :fwd_alloc, :wmem_queued, :ropt_mem, :back_log, :sock_drop
15
+ )
16
+ expect(Kanrisuru::Core::Socket::TCP_STATES).to eq(
17
+ %w[
18
+ established syn-sent syn-recv
19
+ fin-wait-1 fin-wait-2 time-wait
20
+ closed close-wait last-ack listening closing
21
+ ]
22
+ )
23
+ expect(Kanrisuru::Core::Socket::OTHER_STATES).to eq(
24
+ %w[
25
+ all connected synchronized bucket syn-recv
26
+ big
27
+ ]
28
+ )
29
+ expect(Kanrisuru::Core::Socket::TCP_STATE_ABBR).to eq(
30
+ {
31
+ 'ESTAB' => 'established', 'LISTEN' => 'listening', 'UNCONN' => 'unconnected',
32
+ 'SYN-SENT' => 'syn-sent', 'SYN-RECV' => 'syn-recv', 'FIN-WAIT-1' => 'fin-wait-1',
33
+ 'FIN-WAIT-2' => 'fin-wait-2', 'TIME-WAIT' => 'time-wait', 'CLOSE-WAIT' => 'close-wait',
34
+ 'LAST-ACK' => 'last-ack', 'CLOSING' => 'closing'
35
+ }
36
+ )
37
+ end
38
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Stat do
6
+ it 'responds to stat fields' do
7
+ expect(Kanrisuru::Core::Stat::FileStat.new).to respond_to(
8
+ :mode, :blocks, :device, :file_type,
9
+ :gid, :group, :links, :inode,
10
+ :path, :fsize, :uid, :user,
11
+ :last_access, :last_modified, :last_changed
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::System do
6
+ it 'responds to system fields' do
7
+ expect(Kanrisuru::Core::System::CPUArchitectureVulnerability.new).to respond_to(
8
+ :name,
9
+ :data
10
+ )
11
+ expect(Kanrisuru::Core::System::CPUArchitecture.new).to respond_to(
12
+ :architecture,
13
+ :cores,
14
+ :byte_order,
15
+ :address_sizes,
16
+ :operation_modes,
17
+ :online_cpus,
18
+ :threads_per_core,
19
+ :cores_per_socket,
20
+ :sockets,
21
+ :numa_mode,
22
+ :vendor_id,
23
+ :cpu_family,
24
+ :model,
25
+ :model_name,
26
+ :stepping,
27
+ :cpu_mhz,
28
+ :cpu_max_mhz,
29
+ :cpu_min_mhz,
30
+ :bogo_mips,
31
+ :virtualization,
32
+ :hypervisor_vendor,
33
+ :virtualization_type,
34
+ :l1d_cache,
35
+ :l1i_cache,
36
+ :l2_cache,
37
+ :l3_cache,
38
+ :numa_nodes,
39
+ :vulnerabilities,
40
+ :flags
41
+ )
42
+ expect(Kanrisuru::Core::System::KernelStatisticCpu.new).to respond_to(
43
+ :user,
44
+ :nice,
45
+ :system,
46
+ :idle,
47
+ :iowait,
48
+ :irq,
49
+ :softirq,
50
+ :steal,
51
+ :guest,
52
+ :guest_nice
53
+ )
54
+ expect(Kanrisuru::Core::System::KernelStatistic.new).to respond_to(
55
+ :cpu_total,
56
+ :cpus,
57
+ :interrupt_total,
58
+ :interrupts,
59
+ :ctxt,
60
+ :btime,
61
+ :processes,
62
+ :procs_running,
63
+ :procs_blocked,
64
+ :softirq_total,
65
+ :softirqs
66
+ )
67
+ expect(Kanrisuru::Core::System::ProcessInfo.new).to respond_to(
68
+ :uid, :user, :gid, :group, :ppid, :pid,
69
+ :cpu_usage, :memory_usage, :stat, :priority,
70
+ :flags, :policy_abbr, :policy, :cpu_time, :command
71
+ )
72
+ expect(Kanrisuru::Core::System::Uptime.new).to respond_to(
73
+ :boot_time, :uptime, :seconds, :minutes, :hours, :days
74
+ )
75
+ expect(Kanrisuru::Core::System::UserLoggedIn.new).to respond_to(
76
+ :user, :tty, :ip, :login, :idle, :jcpu, :pcpu, :command
77
+ )
78
+ expect(Kanrisuru::Core::System::OpenFile.new).to respond_to(
79
+ :command,
80
+ :pid,
81
+ :uid,
82
+ :file_descriptor,
83
+ :type,
84
+ :device,
85
+ :fsize,
86
+ :inode,
87
+ :name
88
+ )
89
+ end
90
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Transfer do
6
+ it 'responds to transfer fields' do
7
+ expect(Kanrisuru::Core::Transfer::WGET_FILENAME_MODES).to eq(
8
+ %w[unix windows nocontrol ascii lowercase uppercase]
9
+ )
10
+
11
+ expect(Kanrisuru::Core::Transfer::WGET_SSL_PROTO).to eq(
12
+ %w[auto SSLv2 SSLv3 TLSv1]
13
+ )
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::User do
6
+ it 'responds to user fields' do
7
+ expect(Kanrisuru::Core::User::User.new).to respond_to(:uid, :name, :home, :shell, :groups)
8
+ expect(Kanrisuru::Core::User::UserGroup.new).to respond_to(:gid, :name)
9
+ expect(Kanrisuru::Core::User::FilePath.new).to respond_to(:path)
10
+ end
11
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ RSpec.describe Kanrisuru::Core::Yum do
6
+ it 'responds to yum fields' do
7
+ expect(Kanrisuru::Core::Yum::PackageOverview.new).to respond_to(
8
+ :package, :architecture, :version, :installed
9
+ )
10
+
11
+ expect(Kanrisuru::Core::Yum::PackageSearchResult.new).to respond_to(
12
+ :package, :architecture, :summary
13
+ )
14
+
15
+ expect(Kanrisuru::Core::Yum::PackageDetail.new).to respond_to(
16
+ :package,
17
+ :version,
18
+ :release,
19
+ :architecture,
20
+ :install_size,
21
+ :source,
22
+ :yum_id,
23
+ :repository,
24
+ :summary,
25
+ :url,
26
+ :license,
27
+ :description
28
+ )
29
+
30
+ expect(Kanrisuru::Core::Yum::Repolist.new).to respond_to(
31
+ :id,
32
+ :name,
33
+ :status,
34
+ :revision,
35
+ :packages,
36
+ :available_packages,
37
+ :repo_size,
38
+ :mirrors,
39
+ :metalink,
40
+ :updated,
41
+ :baseurl,
42
+ :expire,
43
+ :filters,
44
+ :filename
45
+ )
46
+ end
47
+ end
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.5.0
4
+ version: 0.7.0
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-07-29 00:00:00.000000000 Z
11
+ date: 2021-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -114,6 +114,9 @@ executables: []
114
114
  extensions: []
115
115
  extra_rdoc_files: []
116
116
  files:
117
+ - ".github/CONTRIBUTING.md"
118
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
119
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
117
120
  - ".gitignore"
118
121
  - ".rspec"
119
122
  - ".rubocop.yml"
@@ -199,7 +202,21 @@ files:
199
202
  - spec/helper/test_hosts.rb
200
203
  - spec/hosts.json
201
204
  - spec/spec_helper.rb
205
+ - spec/unit/core/apt_spec.rb
206
+ - spec/unit/core/archive_spec.rb
207
+ - spec/unit/core/disk_spec.rb
202
208
  - spec/unit/core/dmi_spec.rb
209
+ - spec/unit/core/file_spec.rb
210
+ - spec/unit/core/find_spec.rb
211
+ - spec/unit/core/group_spec.rb
212
+ - spec/unit/core/ip_spec.rb
213
+ - spec/unit/core/path_spec.rb
214
+ - spec/unit/core/socket_spec.rb
215
+ - spec/unit/core/stat_spec.rb
216
+ - spec/unit/core/system_spec.rb
217
+ - spec/unit/core/transfer_spec.rb
218
+ - spec/unit/core/user_spec.rb
219
+ - spec/unit/core/yum_spec.rb
203
220
  - spec/unit/core/zypper_spec.rb
204
221
  - spec/unit/fstab_spec.rb
205
222
  - spec/unit/kanrisuru_spec.rb
@@ -212,6 +229,7 @@ licenses:
212
229
  - MIT
213
230
  metadata:
214
231
  source_code_uri: https://github.com/avamia/kanrisuru/
232
+ changelog_uri: https://github.com/avamia/kanrisuru/blob/main/CHANGELOG.md
215
233
  post_install_message:
216
234
  rdoc_options: []
217
235
  require_paths: