linux_admin 1.2.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/lib/linux_admin.rb +0 -8
  3. data/lib/linux_admin/disk.rb +12 -5
  4. data/lib/linux_admin/registration_system.rb +8 -4
  5. data/lib/linux_admin/scap.rb +1 -1
  6. data/lib/linux_admin/service/sys_v_init_service.rb +2 -1
  7. data/lib/linux_admin/service/systemd_service.rb +6 -2
  8. data/lib/linux_admin/version.rb +1 -1
  9. metadata +8 -100
  10. data/lib/linux_admin/registration_system/rhn.rb +0 -111
  11. data/spec/chrony_spec.rb +0 -64
  12. data/spec/common_spec.rb +0 -37
  13. data/spec/data/rhn/output_rhn-channel_list +0 -2
  14. data/spec/data/rhn/output_rhn-channel_list_available +0 -4
  15. data/spec/data/rhn/systemid +0 -57
  16. data/spec/data/rhn/systemid.missing_system_id +0 -57
  17. data/spec/data/rpm/cmd_output_for_list_installed +0 -20
  18. data/spec/data/subscription_manager/output_list_all_available +0 -42
  19. data/spec/data/subscription_manager/output_list_installed_not_subscribed +0 -19
  20. data/spec/data/subscription_manager/output_list_installed_subscribed +0 -19
  21. data/spec/data/subscription_manager/output_orgs +0 -6
  22. data/spec/data/subscription_manager/output_repos +0 -18
  23. data/spec/data/time_date/timedatectl_output +0 -14
  24. data/spec/data/yum/first.repo +0 -19
  25. data/spec/data/yum/output_repo_list +0 -13
  26. data/spec/data/yum/output_repoquery_multiple +0 -3
  27. data/spec/data/yum/output_repoquery_single +0 -1
  28. data/spec/data/yum/second.repo +0 -9
  29. data/spec/deb_spec.rb +0 -52
  30. data/spec/disk_spec.rb +0 -307
  31. data/spec/distro_spec.rb +0 -77
  32. data/spec/dns_spec.rb +0 -105
  33. data/spec/etc_issue_spec.rb +0 -37
  34. data/spec/fstab_spec.rb +0 -132
  35. data/spec/hardware_spec.rb +0 -46
  36. data/spec/hosts_spec.rb +0 -150
  37. data/spec/ip_address_spec.rb +0 -148
  38. data/spec/logical_volume_spec.rb +0 -166
  39. data/spec/mountable_spec.rb +0 -182
  40. data/spec/network_interface/network_interface_rh_spec.rb +0 -291
  41. data/spec/network_interface_spec.rb +0 -284
  42. data/spec/partition_spec.rb +0 -24
  43. data/spec/physical_volume_spec.rb +0 -101
  44. data/spec/registration_system_spec.rb +0 -85
  45. data/spec/rhn_spec.rb +0 -144
  46. data/spec/rpm_spec.rb +0 -85
  47. data/spec/scap_spec.rb +0 -48
  48. data/spec/service/sys_v_init_service_spec.rb +0 -127
  49. data/spec/service/systemd_service_spec.rb +0 -133
  50. data/spec/service_spec.rb +0 -54
  51. data/spec/spec_helper.rb +0 -116
  52. data/spec/ssh_spec.rb +0 -53
  53. data/spec/subscription_manager_spec.rb +0 -228
  54. data/spec/system_spec.rb +0 -15
  55. data/spec/time_date_spec.rb +0 -106
  56. data/spec/volume_group_spec.rb +0 -99
  57. data/spec/yum_spec.rb +0 -155
@@ -1,37 +0,0 @@
1
- describe LinuxAdmin::Common do
2
- describe "#cmd" do
3
- it "looks up local command from id" do
4
- expect(described_class.cmd(:dd)).to match(%r{bin/dd})
5
- end
6
-
7
- it "returns nil when it can't find the command" do
8
- expect(described_class.cmd(:kasgbdlcvjhals)).to be_nil
9
- end
10
- end
11
-
12
- describe "#cmd?" do
13
- it "returns true when the command exists" do
14
- expect(described_class.cmd?(:dd)).to be true
15
- end
16
-
17
- it "returns false when the command doesn't exist" do
18
- expect(described_class.cmd?(:kasgbdlcvjhals)).to be false
19
- end
20
- end
21
-
22
- [described_class, LinuxAdmin].each do |klass|
23
- describe "#{klass}.run" do
24
- it "runs a command with AwesomeSpawn.run" do
25
- expect(AwesomeSpawn).to receive(:run).with("echo", nil => "test")
26
- klass.run("echo", nil => "test")
27
- end
28
- end
29
-
30
- describe "#{klass}.run!" do
31
- it "runs a command with AwesomeSpawn.run!" do
32
- expect(AwesomeSpawn).to receive(:run!).with("echo", nil => "test")
33
- klass.run!("echo", nil => "test")
34
- end
35
- end
36
- end
37
- end
@@ -1,2 +0,0 @@
1
- rhel-x86_64-server-6
2
- rhel-x86_64-server-6-cf-me-2
@@ -1,4 +0,0 @@
1
- rhel-x86_64-server-6-cf-me-2
2
- rhel-x86_64-server-6-cf-me-2-beta
3
- rhel-x86_64-server-6-cf-me-3
4
- rhel-x86_64-server-6-cf-me-3-beta
@@ -1,57 +0,0 @@
1
- <?xml version="1.0"?>
2
- <params>
3
- <param>
4
- <value><struct>
5
- <member>
6
- <name>username</name>
7
- <value><string>SomeUsername</string></value>
8
- </member>
9
- <member>
10
- <name>operating_system</name>
11
- <value><string>redhat-release-server</string></value>
12
- </member>
13
- <member>
14
- <name>description</name>
15
- <value><string>Initial Registration Parameters:
16
- OS: redhat-release-server
17
- Release: 6Server
18
- CPU Arch: x86_64</string></value>
19
- </member>
20
- <member>
21
- <name>checksum</name>
22
- <value><string>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string></value>
23
- </member>
24
- <member>
25
- <name>profile_name</name>
26
- <value><string>SomeProfileName</string></value>
27
- </member>
28
- <member>
29
- <name>system_id</name>
30
- <value><string>ID-0123456789</string></value>
31
- </member>
32
- <member>
33
- <name>architecture</name>
34
- <value><string>x86_64</string></value>
35
- </member>
36
- <member>
37
- <name>os_release</name>
38
- <value><string>6Server</string></value>
39
- </member>
40
- <member>
41
- <name>fields</name>
42
- <value><array><data>
43
- <value><string>system_id</string></value>
44
- <value><string>os_release</string></value>
45
- <value><string>operating_system</string></value>
46
- <value><string>architecture</string></value>
47
- <value><string>username</string></value>
48
- <value><string>type</string></value>
49
- </data></array></value>
50
- </member>
51
- <member>
52
- <name>type</name>
53
- <value><string>REAL</string></value>
54
- </member>
55
- </struct></value>
56
- </param>
57
- </params>
@@ -1,57 +0,0 @@
1
- <?xml version="1.0"?>
2
- <params>
3
- <param>
4
- <value><struct>
5
- <member>
6
- <name>username</name>
7
- <value><string>SomeUsername</string></value>
8
- </member>
9
- <member>
10
- <name>operating_system</name>
11
- <value><string>redhat-release-server</string></value>
12
- </member>
13
- <member>
14
- <name>description</name>
15
- <value><string>Initial Registration Parameters:
16
- OS: redhat-release-server
17
- Release: 6Server
18
- CPU Arch: x86_64</string></value>
19
- </member>
20
- <member>
21
- <name>checksum</name>
22
- <value><string>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</string></value>
23
- </member>
24
- <member>
25
- <name>profile_name</name>
26
- <value><string>SomeProfileName</string></value>
27
- </member>
28
- <member>
29
- <name>system_id</name>
30
- <value><string></string></value>
31
- </member>
32
- <member>
33
- <name>architecture</name>
34
- <value><string>x86_64</string></value>
35
- </member>
36
- <member>
37
- <name>os_release</name>
38
- <value><string>6Server</string></value>
39
- </member>
40
- <member>
41
- <name>fields</name>
42
- <value><array><data>
43
- <value><string>system_id</string></value>
44
- <value><string>os_release</string></value>
45
- <value><string>operating_system</string></value>
46
- <value><string>architecture</string></value>
47
- <value><string>username</string></value>
48
- <value><string>type</string></value>
49
- </data></array></value>
50
- </member>
51
- <member>
52
- <name>type</name>
53
- <value><string>REAL</string></value>
54
- </member>
55
- </struct></value>
56
- </param>
57
- </params>
@@ -1,20 +0,0 @@
1
- ruby193-rubygem-some_really_long_name 1.0.7-1.el6
2
- fipscheck-lib 1.2.0-7.el6
3
- aic94xx-firmware 30-2.el6
4
- latencytop-common 0.5-9.el6
5
- uuid 1.6.1-10.el6
6
- ConsoleKit 0.4.1-3.el6
7
- cpuspeed 1.5-19.el6
8
- mailcap 2.1.31-2.el6
9
- freetds 0.82-7.1.el6cf
10
- elinks 0.12-0.21.pre5.el6_3
11
- abrt-cli 2.0.8-15.el6
12
- libattr 2.4.44-7.el6
13
- passwd 0.77-4.el6_2.2
14
- vim-enhanced 7.2.411-1.8.el6
15
- popt 1.13-7.el6
16
- hesiod 3.1.0-19.el6
17
- pinfo 0.6.9-12.el6
18
- libpng 1.2.49-1.el6_2
19
- libdhash 0.4.2-9.el6
20
- zlib-devel 1.2.3-29.el6
@@ -1,42 +0,0 @@
1
- +-------------------------------------------+
2
- Available Subscriptions
3
- +-------------------------------------------+
4
- Subscription Name: Example Subscription
5
- SKU: SER0123
6
- Pool Id: 82c042fca983889b10178893f29b06e3
7
- Quantity: 1690
8
- Service Level: None
9
- Service Type: None
10
- Multi-Entitlement: No
11
- Ends: 01/01/2022
12
- System Type: Physical
13
-
14
- Subscription Name: My Private Subscription
15
- SKU: SER9876
16
- Pool Id: 4f738052ec866192c775c62f408ab868
17
- Quantity: Unlimited
18
- Service Level: None
19
- Service Type: None
20
- Multi-Entitlement: No
21
- Ends: 06/04/2013
22
- System Type: Virtual
23
-
24
- Subscription Name: Shared Subscription - With other characters, (2 sockets) (Up to 1 guest)
25
- SKU: RH0123456
26
- Pool Id: 3d81297f352305b9a3521981029d7d83
27
- Quantity: 1
28
- Service Level: Self-support
29
- Service Type: L1-L3
30
- Multi-Entitlement: No
31
- Ends: 05/15/2013
32
- System Type: Virtual
33
-
34
- Subscription Name: Example Subscription, Premium (up to 2 sockets) 3 year
35
- SKU: MCT0123A9
36
- Pool Id: 87cefe63b67984d5c7e401d833d2f87f
37
- Quantity: 1
38
- Service Level: Premium
39
- Service Type: L1-L3
40
- Multi-Entitlement: No
41
- Ends: 07/05/2013
42
- System Type: Virtual
@@ -1,19 +0,0 @@
1
- +-------------------------------------------+
2
- Installed Product Status
3
- +-------------------------------------------+
4
- Product Name: Red Hat Enterprise Linux Server
5
- Product ID: 69
6
- Version: 6.3
7
- Arch: x86_64
8
- Status: Not Subscribed
9
- Starts: 09/27/2012
10
- Ends: 09/26/2013
11
-
12
- Product Name: Red Hat CloudForms
13
- Product ID: 167
14
- Version: 2.1
15
- Arch: x86_64
16
- Status: Subscribed
17
- Starts: 01/03/2013
18
- Ends:
19
-
@@ -1,19 +0,0 @@
1
- +-------------------------------------------+
2
- Installed Product Status
3
- +-------------------------------------------+
4
- Product Name: Red Hat Enterprise Linux Server
5
- Product ID: 69
6
- Version: 6.3
7
- Arch: x86_64
8
- Status: Subscribed
9
- Starts: 09/27/2012
10
- Ends: 09/26/2013
11
-
12
- Product Name: Red Hat CloudForms
13
- Product ID: 167
14
- Version: 2.1
15
- Arch: x86_64
16
- Status: Subscribed
17
- Starts: 01/03/2013
18
- Ends: 01/03/2014
19
-
@@ -1,6 +0,0 @@
1
- +-------------------------------------------+
2
- myUser Organizations
3
- +-------------------------------------------+
4
-
5
- Name: SomeOrg
6
- Key: 1234567
@@ -1,18 +0,0 @@
1
- +----------------------------------------------------------+
2
- Available Repositories in /etc/yum.repos.d/redhat.repo
3
- +----------------------------------------------------------+
4
- Repo ID: some-repo-source-rpms
5
- Repo Name: Some Repo (Source RPMs)
6
- Repo URL: https://my.host.example.com/repos/some-repo/source/rpms
7
- Enabled: 1
8
-
9
- Repo ID: some-repo-rpms
10
- Repo Name: Some Repo
11
- Repo URL: https://my.host.example.com/repos/some-repo/rpms
12
- Enabled: 1
13
-
14
- Repo ID: some-repo-2-beta-rpms
15
- Repo Name: Some Repo (Beta RPMs)
16
- Repo URL: https://my.host.example.com/repos/some-repo-2/beta/rpms
17
- Enabled: 0
18
-
@@ -1,14 +0,0 @@
1
- Local time: Thu 2015-09-24 17:54:02 EDT
2
- Universal time: Thu 2015-09-24 21:54:02 UTC
3
- RTC time: Thu 2015-09-24 21:54:02
4
- Time zone: America/New_York (EDT, -0400)
5
- NTP enabled: yes
6
- NTP synchronized: yes
7
- RTC in local TZ: no
8
- DST active: yes
9
- Last DST change: DST began at
10
- Sun 2015-03-08 01:59:59 EST
11
- Sun 2015-03-08 03:00:00 EDT
12
- Next DST change: DST ends (the clock jumps one hour backwards) at
13
- Sun 2015-11-01 01:59:59 EDT
14
- Sun 2015-11-01 01:00:00 EST
@@ -1,19 +0,0 @@
1
- [my-local-repo-a]
2
- name = My Local Repo A
3
- baseurl = https://mirror.example.com/a/content/os_ver
4
- enabled = 0
5
- gpgcheck = 1
6
- gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-my-local-server
7
- sslverify = 1
8
- sslcacert = /etc/rhsm/ca/my-loacl-server.pem
9
- sslclientkey = /etc/pki/entitlement/0123456789012345678-key.pem
10
- sslclientcert = /etc/pki/entitlement/0123456789012345678.pem
11
- metadata_expire = 86400
12
-
13
- [my-local-repo-b]
14
- name = My Local Repo B
15
- baseurl = https://mirror.example.com/b/content/os_ver
16
- enabled = 1
17
- gpgcheck = 0
18
- sslverify = 0
19
- metadata_expire = 86400
@@ -1,13 +0,0 @@
1
- Loaded plugins: product-id, rhnplugin, security, subscription-manager
2
- This system is receiving updates from Red Hat Subscription Management.
3
- This system is not registered with RHN Classic or RHN Satellite.
4
- You can use rhn_register to register.
5
- RHN Satellite or RHN Classic support will be disabled.
6
- rhel-6-server-rpms | 3.7 kB 00:00
7
- rhel-ha-for-rhel-6-server-rpms | 3.7 kB 00:00
8
- rhel-lb-for-rhel-6-server-rpms | 3.7 kB 00:00
9
- repo id repo name status
10
- rhel-6-server-rpms Red Hat Enterprise Linux 6 Server (RPMs) 11,016
11
- rhel-ha-for-rhel-6-server-rpms Red Hat Enterprise Linux High Availability (for RHEL 6 Server) (RPMs) 269
12
- rhel-lb-for-rhel-6-server-rpms Red Hat Enterprise Linux Load Balancer (for RHEL 6 Server) (RPMs) 0
13
- repolist: 11,909
@@ -1,3 +0,0 @@
1
- curl 7.19.7
2
- subscription-manager 1.1.23.1
3
- wget 1.12
@@ -1 +0,0 @@
1
- subscription-manager 1.1.23.1
@@ -1,9 +0,0 @@
1
- [my-local-repo-c]
2
- name=My Local Repo c
3
- baseurl=https://mirror.example.com/c/content/os_ver
4
- enabled=0
5
- cost=100
6
- gpgcheck=1
7
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-my-local-server
8
- sslverify=0
9
- metadata_expire=1
@@ -1,52 +0,0 @@
1
- describe LinuxAdmin::Deb do
2
- describe "#info" do
3
- it "returns package metadata" do
4
- # as output w/ apt-cache show ruby on ubuntu 13.04
5
- data = <<EOS
6
- Package: ruby
7
- Priority: optional
8
- Section: interpreters
9
- Installed-Size: 31
10
- Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
11
- Original-Maintainer: akira yamada <akira@debian.org>
12
- Architecture: all
13
- Source: ruby-defaults
14
- Version: 4.9
15
- Replaces: irb, rdoc
16
- Provides: irb, rdoc
17
- Depends: ruby1.9.1 (>= 1.9.3.194-1)
18
- Suggests: ri, ruby-dev
19
- Conflicts: irb, rdoc
20
- Filename: pool/main/r/ruby-defaults/ruby_4.9_all.deb
21
- Size: 4896
22
- MD5sum: b1991f2e0eafb04f5930ed242cfe1476
23
- SHA1: a7c55fbb83dd8382631ea771b5555d989351f840
24
- SHA256: 84d042e0273bd2f0082dd9e7dda0246267791fd09607041a35485bfff92f38d9
25
- Description-en: Interpreter of object-oriented scripting language Ruby (default version)
26
- Ruby is the interpreted scripting language for quick and easy
27
- object-oriented programming. It has many features to process text
28
- files and to do system management tasks (as in perl). It is simple,
29
- straight-forward, and extensible.
30
- .
31
- This package is a dependency package, which depends on Debian's default Ruby
32
- version (currently v1.9.3).
33
- Homepage: http://www.ruby-lang.org/
34
- Description-md5: da2991b37e3991230d79ba70f9c01682
35
- Bugs: https://bugs.launchpad.net/ubuntu/+filebug
36
- Origin: Ubuntu
37
- Supported: 9m
38
- Task: kubuntu-desktop, kubuntu-full, kubuntu-active, kubuntu-active-desktop, kubuntu-active-full, kubuntu-active, edubuntu-desktop-gnome, ubuntustudio-font-meta
39
- EOS
40
- expect(LinuxAdmin::Common).to receive(:run!)
41
- .with(described_class::APT_CACHE_CMD, :params => %w(show ruby))
42
- .and_return(double(:output => data))
43
- metadata = described_class.info("ruby")
44
- expect(metadata['package']).to eq('ruby')
45
- expect(metadata['priority']).to eq('optional')
46
- expect(metadata['section']).to eq('interpreters')
47
- expect(metadata['architecture']).to eq('all')
48
- expect(metadata['version']).to eq('4.9')
49
- expect(metadata['origin']).to eq('Ubuntu')
50
- end
51
- end
52
- end
@@ -1,307 +0,0 @@
1
- describe LinuxAdmin::Disk do
2
- describe "#local" do
3
- it "returns local disks" do
4
- expect(LinuxAdmin::Common).to receive(:run!).with(
5
- LinuxAdmin::Common.cmd(:lsblk),
6
- :params => {:d => nil, :n => nil, :p => nil, :o => "NAME"}
7
- ).and_return(double("result", :output => "/dev/hda\n/dev/sda"))
8
- disks = LinuxAdmin::Disk.local
9
- paths = disks.collect { |disk| disk.path }
10
- expect(paths).to include('/dev/hda')
11
- expect(paths).to include('/dev/sda')
12
- end
13
- end
14
-
15
- describe "#size" do
16
- it "uses fdisk" do
17
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
18
- expect(LinuxAdmin::Common).to receive(:run!)
19
- .with(LinuxAdmin::Common.cmd(:fdisk),
20
- :params => {"-l" => nil})
21
- .and_return(double(:output => ""))
22
- disk.size
23
- end
24
-
25
- it "returns disk size" do
26
- fdisk = <<eos
27
- Disk /dev/hda: 500.1 GB, 500107862016 bytes
28
- 255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
29
- Units = sectors of 1 * 512 = 512 bytes
30
- Sector size (logical/physical): 512 bytes / 512 bytes
31
- I/O size (minimum/optimal): 512 bytes / 512 bytes
32
- Disk identifier: 0x3ddb508b
33
-
34
- Device Boot Start End Blocks Id System
35
- 1 1259MB 81.8GB 80.5GB primary ntfs
36
- 2 81.8GB 162GB 80.5GB primary ext4
37
- 3 162GB 163GB 1074MB logical linux-swap(v1)
38
- eos
39
-
40
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
41
- allow(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => fdisk))
42
- expect(disk.size).to eq(500_107_862_016)
43
- end
44
- end
45
-
46
- describe "#partitions" do
47
- it "uses parted" do
48
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
49
- expect(LinuxAdmin::Common).to receive(:run)
50
- .with(LinuxAdmin::Common.cmd(:parted),
51
- :params => {nil => %w(--script /dev/hda print)}).and_return(double(:output => ""))
52
- disk.partitions
53
- end
54
-
55
- it "returns [] on non-zero parted rc" do
56
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
57
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "", :exit_status => 1))
58
- expect(disk.partitions).to eq([])
59
- end
60
-
61
- context "with nvme parted output" do
62
- let(:parted_output) do
63
- <<~PARTED
64
- Model: NVMe Device (nvme)
65
- Disk /dev/nvme0n1: 512GB
66
- Sector size (logical/physical): 512B/512B
67
- Partition Table: msdos
68
- Disk Flags:
69
-
70
- Number Start End Size Type File system Flags
71
- 1 1049kB 1075MB 1074MB primary ext4 boot
72
- 2 1075MB 17.7GB 16.6GB primary
73
- 3 17.7GB 512GB 494GB primary
74
-
75
- PARTED
76
- end
77
-
78
- it "sets partitons" do
79
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => parted_output))
80
- disk = LinuxAdmin::Disk.new(:path => "/dev/nvme0n1")
81
- partitions = disk.partitions
82
-
83
- expect(disk.model).to eq("nvme")
84
-
85
- expect(partitions[0].id).to eq(1)
86
- expect(partitions[0].disk).to eq(disk)
87
- expect(partitions[0].size).to eq(1_126_170_624.0)
88
- expect(partitions[0].start_sector).to eq(1_074_176.0)
89
- expect(partitions[0].end_sector).to eq(1_127_219_200.0)
90
- expect(partitions[0].partition_type).to eq('primary')
91
- expect(partitions[0].fs_type).to eq('ext4')
92
- expect(partitions[0].path).to eq('/dev/nvme0n1p1')
93
- expect(partitions[1].id).to eq(2)
94
- expect(partitions[1].disk).to eq(disk)
95
- expect(partitions[1].size).to eq(17_824_114_278.4)
96
- expect(partitions[1].start_sector).to eq(1_127_219_200.0)
97
- expect(partitions[1].end_sector).to eq(19_005_230_284.8)
98
- expect(partitions[1].partition_type).to eq('primary')
99
- expect(partitions[1].path).to eq('/dev/nvme0n1p2')
100
- expect(partitions[2].id).to eq(3)
101
- expect(partitions[2].disk).to eq(disk)
102
- expect(partitions[2].size).to eq(530_428_461_056.0)
103
- expect(partitions[2].start_sector).to eq(19_005_230_284.8)
104
- expect(partitions[2].end_sector).to eq(549_755_813_888.0)
105
- expect(partitions[2].partition_type).to eq('primary')
106
- expect(partitions[2].path).to eq('/dev/nvme0n1p3')
107
- end
108
- end
109
-
110
- context "with scsi parted output" do
111
- let(:parted_output) do
112
- <<~PARTED
113
- Model: ATA TOSHIBA MK5061GS (scsi)
114
- Disk /dev/sda: 500GB
115
- Sector size (logical/physical): 512B/512B
116
- Partition Table: msdos
117
- Disk Flags:
118
-
119
- Number Start End Size Type File system Flags
120
- 1 1259kB 81.8GB 80.5GB primary ntfs
121
- 2 81.8GB 162GB 80.5GB primary ext4
122
- 3 162GB 163GB 1074MB logical linux-swap(v1)
123
-
124
- PARTED
125
- end
126
-
127
- it "sets partitons" do
128
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => parted_output))
129
- disk = LinuxAdmin::Disk.new(:path => "/dev/sda")
130
- partitions = disk.partitions
131
-
132
- expect(disk.model).to eq("scsi")
133
-
134
- expect(partitions[0].id).to eq(1)
135
- expect(partitions[0].disk).to eq(disk)
136
- expect(partitions[0].size).to eq(86_436_216_832.0)
137
- expect(partitions[0].start_sector).to eq(1_289_216.0)
138
- expect(partitions[0].end_sector).to eq(87_832_081_203.2)
139
- expect(partitions[0].partition_type).to eq('primary')
140
- expect(partitions[0].fs_type).to eq('ntfs')
141
- expect(partitions[0].path).to eq('/dev/sda1')
142
- expect(partitions[1].id).to eq(2)
143
- expect(partitions[1].disk).to eq(disk)
144
- expect(partitions[1].size).to eq(86_436_216_832.0)
145
- expect(partitions[1].start_sector).to eq(87_832_081_203.2)
146
- expect(partitions[1].end_sector).to eq(173_946_175_488)
147
- expect(partitions[1].partition_type).to eq('primary')
148
- expect(partitions[1].fs_type).to eq('ext4')
149
- expect(partitions[1].path).to eq('/dev/sda2')
150
- expect(partitions[2].id).to eq(3)
151
- expect(partitions[2].disk).to eq(disk)
152
- expect(partitions[2].size).to eq(1_126_170_624)
153
- expect(partitions[2].start_sector).to eq(173_946_175_488)
154
- expect(partitions[2].end_sector).to eq(175_019_917_312)
155
- expect(partitions[2].partition_type).to eq('logical')
156
- expect(partitions[2].fs_type).to eq('linux-swap(v1)')
157
- expect(partitions[2].path).to eq('/dev/sda3')
158
- end
159
- end
160
- end
161
-
162
- describe "#create_partitions" do
163
- before(:each) do
164
- @disk = LinuxAdmin::Disk.new(:path => '/dev/hda')
165
- end
166
-
167
- it "dispatches to create_partition" do
168
- expect(@disk).to receive(:create_partition).with("primary", "0%", "50%")
169
- @disk.create_partitions "primary", :start => "0%", :end => "50%"
170
- end
171
-
172
- context "multiple partitions specified" do
173
- it "calls create_partition for each partition" do
174
- expect(@disk).to receive(:create_partition).with("primary", "0%", "49%")
175
- expect(@disk).to receive(:create_partition).with("primary", "50%", "100%")
176
- @disk.create_partitions("primary", {:start => "0%", :end => "49%"},
177
- {:start => "50%", :end => "100%"})
178
- end
179
-
180
- context "partitions overlap" do
181
- it "raises argument error" do
182
- expect{
183
- @disk.create_partitions("primary", {:start => "0%", :end => "50%"},
184
- {:start => "49%", :end => "100%"})
185
- }.to raise_error(ArgumentError)
186
- end
187
- end
188
- end
189
- end
190
-
191
- describe "#create_partition" do
192
- before(:each) do
193
- # test disk w/ existing partition
194
- @disk = LinuxAdmin::Disk.new :path => '/dev/hda'
195
- @disk.instance_variable_set(:@partitions,
196
- [LinuxAdmin::Partition.new(:id => 1,
197
- :end_sector => 1024)])
198
- allow(@disk).to receive_messages(:has_partition_table? => true)
199
- end
200
-
201
- it "uses parted" do
202
- params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', 1024, 2048]
203
- expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), :params => {nil => params})
204
- @disk.create_partition 'primary', 1024
205
- end
206
-
207
- it "accepts start/end params" do
208
- params = ['--script', '/dev/hda', 'mkpart', '-a', 'opt', 'primary', "0%", "50%"]
209
- expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), :params => {nil => params})
210
- @disk.create_partition 'primary', "0%", "50%"
211
- end
212
-
213
- context "missing params" do
214
- it "raises ArgumentError" do
215
- expect{
216
- @disk.create_partition 'primary'
217
- }.to raise_error(ArgumentError)
218
-
219
- expect{
220
- @disk.create_partition 'primary', '0%', '50%', 100
221
- }.to raise_error(ArgumentError)
222
- end
223
- end
224
-
225
- it "returns partition" do
226
- expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
227
- partition = @disk.create_partition 'primary', 1024
228
- expect(partition).to be_an_instance_of(LinuxAdmin::Partition)
229
- end
230
-
231
- it "increments partition id" do
232
- expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
233
- partition = @disk.create_partition 'primary', 1024
234
- expect(partition.id).to eq(2)
235
- end
236
-
237
- it "sets partition start to first unused sector on disk" do
238
- expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
239
- partition = @disk.create_partition 'primary', 1024
240
- expect(partition.start_sector).to eq(1024)
241
- end
242
-
243
- it "stores new partition locally" do
244
- expect(LinuxAdmin::Common).to receive(:run!) # stub out call to parted
245
- expect {
246
- @disk.create_partition 'primary', 1024
247
- }.to change{@disk.partitions.size}.by(1)
248
- end
249
-
250
- it "creates partition table if missing" do
251
- allow(@disk).to receive_messages(:has_partition_table? => false)
252
- expect(@disk).to receive(:create_partition_table)
253
- expect(LinuxAdmin::Common).to receive(:run!)
254
- @disk.create_partition 'primary', 1024
255
- end
256
- end
257
-
258
- describe "#has_partition_table?" do
259
- it "positive case" do
260
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
261
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "", :exit_status => 0))
262
- expect(disk).to have_partition_table
263
- end
264
-
265
- it "negative case" do
266
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
267
- output = "\e[?1034h\r\rError: /dev/sdb: unrecognised disk label\n"
268
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => output, :exit_status => 1))
269
- expect(disk).not_to have_partition_table
270
- end
271
- end
272
-
273
- it "#create_partition_table" do
274
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
275
- options = {:params => {nil => %w(--script /dev/hda mklabel msdos)}}
276
- expect(LinuxAdmin::Common).to receive(:run!).with(LinuxAdmin::Common.cmd(:parted), options)
277
- disk.create_partition_table
278
- end
279
-
280
- describe "#clear!" do
281
- it "clears partitions" do
282
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
283
- expect(LinuxAdmin::Common).to receive(:run).and_return(double(:output => "")) # stub out call to cmds
284
- disk.partitions << LinuxAdmin::Partition.new
285
-
286
- expect(LinuxAdmin::Common).to receive(:run!)
287
- disk.clear!
288
- expect(disk.partitions).to be_empty
289
- end
290
-
291
- it "uses dd to clear partition table" do
292
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
293
- expect(LinuxAdmin::Common).to receive(:run!)
294
- .with(LinuxAdmin::Common.cmd(:dd),
295
- :params => {'if=' => '/dev/zero', 'of=' => '/dev/hda',
296
- 'bs=' => 512, 'count=' => 1})
297
- disk.clear!
298
- end
299
-
300
- it "returns self" do
301
- disk = LinuxAdmin::Disk.new :path => '/dev/hda'
302
- allow(LinuxAdmin::Common).to receive(:run!) # stub out call to dd
303
- expect(disk.clear!).to eq(disk)
304
- end
305
- end
306
-
307
- end