linux_admin 0.18.0 → 0.19.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
  SHA1:
3
- metadata.gz: a90ef3973da3f00152bf552f74cab0baa544af95
4
- data.tar.gz: f296bf3c99266062abc2cc1f67d987aa0e974ec2
3
+ metadata.gz: 0909517c6cc080f6c8a9a82a7b1119e3a8c50452
4
+ data.tar.gz: d2182ff8ce82b685d55e562968154010e486874c
5
5
  SHA512:
6
- metadata.gz: c010a5739c54682ca620bfb4b0851d28e785e063225230c0e848472dfb1359876e27ea7880881838e6c93cf1de30a31a470e4b605e301e8af3c642023e9e953b
7
- data.tar.gz: f1f10c4d2bb146033cb405a35b7f510618b7c6cde0d5226b81ea4daa52d6bd44c6a40642ed504f427cebf655ee6784aa4752304c7fed5ed773420a5002c6c942
6
+ metadata.gz: 7ff4ffc9e1c2650ed0c127b1a2338e5476e7caa211198b471288b17f3874aa6a1b84cacbcafdc165eed7ad971e07ee5d4b53270d2bb593ccdfac378cdbbbd029
7
+ data.tar.gz: 9de9c8938028031bfe8f0793fe89f0e8e3dc6b329f4d6711842c43500ba41870f4bb5bf532e22206bd59f048a4879e92201c00c52ba5bc11f0c4e879fd3c49c3
@@ -1,5 +1,7 @@
1
1
  module LinuxAdmin
2
2
  class Chrony
3
+ SERVICE_NAME = "chronyd".freeze
4
+
3
5
  def initialize(conf = "/etc/chrony.conf")
4
6
  raise MissingConfigurationFileError, "#{conf} does not exist" unless File.exist?(conf)
5
7
  @conf = conf
@@ -16,6 +18,14 @@ module LinuxAdmin
16
18
  data << "\n" unless data.end_with?("\n")
17
19
  servers.each { |s| data << "server #{s} iburst\n" }
18
20
  File.write(@conf, data)
21
+ restart_service_if_running
22
+ end
23
+
24
+ private
25
+
26
+ def restart_service_if_running
27
+ service = Service.new(SERVICE_NAME)
28
+ service.restart if service.running?
19
29
  end
20
30
  end
21
31
  end
@@ -26,6 +26,10 @@ module LinuxAdmin
26
26
 
27
27
  alias_method :update_entry, :add_alias
28
28
 
29
+ def set_loopback_hostname(hostname, comment = nil)
30
+ ["::1", "127.0.0.1"].each { |address| add_name(address, hostname, true, comment, false) }
31
+ end
32
+
29
33
  def set_canonical_hostname(address, hostname, comment = nil)
30
34
  add_name(address, hostname, true, comment)
31
35
  end
@@ -46,9 +50,9 @@ module LinuxAdmin
46
50
 
47
51
  private
48
52
 
49
- def add_name(address, hostname, fqdn, comment)
53
+ def add_name(address, hostname, fqdn, comment, remove_existing = true)
50
54
  # Delete entries for this hostname first
51
- @parsed_file.each { |i| i[:hosts].to_a.delete(hostname) }
55
+ @parsed_file.each { |i| i[:hosts].to_a.delete(hostname) } if remove_existing
52
56
 
53
57
  # Add entry
54
58
  line_number = @parsed_file.find_path(address).first
@@ -18,6 +18,12 @@ module LinuxAdmin
18
18
  base.extend(ClassMethods)
19
19
  end
20
20
 
21
+ def discover_mount_point
22
+ result = Common.run!(Common.cmd(:mount))
23
+ mount_line = result.output.split("\n").find { |line| line.split[0] == path }
24
+ @mount_point = mount_line.split[2] if mount_line
25
+ end
26
+
21
27
  def format_to(filesystem)
22
28
  Common.run!(Common.cmd(:mke2fs),
23
29
  :params => {'-t' => filesystem, nil => path})
@@ -25,10 +25,9 @@ module LinuxAdmin
25
25
 
26
26
  def execute_commands(commands, agent_socket, stdin)
27
27
  result = nil
28
- args = {:paranoid => false}
28
+ args = {:paranoid => false, :number_of_password_prompts => 0}
29
29
  if agent_socket
30
30
  args.merge!(:forward_agent => true,
31
- :number_of_password_prompts => 0,
32
31
  :agent_socket_factory => -> { UNIXSocket.open(agent_socket) })
33
32
  elsif @private_key
34
33
  args[:key_data] = [@private_key]
@@ -15,6 +15,13 @@ module LinuxAdmin
15
15
  system_timezone_detailed.split[0]
16
16
  end
17
17
 
18
+ def self.timezones
19
+ result = Common.run!(Common.cmd(COMMAND), :params => ["list-timezones"])
20
+ result.output.split("\n")
21
+ rescue AwesomeSpawn::CommandResultError => e
22
+ raise TimeCommandError, e.message
23
+ end
24
+
18
25
  def self.system_time=(time)
19
26
  Common.run!(Common.cmd(COMMAND), :params => ["set-time", "#{time.strftime("%F %T")}", :adjust_system_clock])
20
27
  rescue AwesomeSpawn::CommandResultError => e
@@ -1,3 +1,3 @@
1
1
  module LinuxAdmin
2
- VERSION = "0.18.0"
2
+ VERSION = "0.19.0"
3
3
  end
@@ -43,11 +43,11 @@ module LinuxAdmin
43
43
  cmd = "yum check-update"
44
44
  params = {nil => packages} unless packages.blank?
45
45
 
46
- exitstatus = Common.run(cmd, :params => params).exit_status
47
- case exitstatus
46
+ spawn = Common.run(cmd, :params => params)
47
+ case spawn.exit_status
48
48
  when 0; false
49
49
  when 100; true
50
- else raise "Error: Exit Code #{exitstatus}"
50
+ else raise "Error: #{cmd} returns '#{spawn.exit_status}', '#{spawn.error}'"
51
51
  end
52
52
  end
53
53
 
data/spec/chrony_spec.rb CHANGED
@@ -35,6 +35,29 @@ EOF
35
35
  expect(File).to receive(:write) do |_file, contents|
36
36
  expect(contents).to eq(CHRONY_CONF + "server baz.example.net iburst\nserver foo.bar.example.com iburst\n")
37
37
  end
38
+ allow(subject).to receive(:restart_service_if_running)
39
+ subject.add_servers("baz.example.net", "foo.bar.example.com")
40
+ end
41
+
42
+ it "restarts the service if it is running" do
43
+ allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
44
+ allow(File).to receive(:write)
45
+
46
+ chronyd_service = double
47
+ expect(LinuxAdmin::Service).to receive(:new).with("chronyd").and_return(chronyd_service)
48
+ expect(chronyd_service).to receive(:running?).and_return true
49
+ expect(chronyd_service).to receive(:restart)
50
+ subject.add_servers("baz.example.net", "foo.bar.example.com")
51
+ end
52
+
53
+ it "doesn't restart the service if it is not running" do
54
+ allow(File).to receive(:read).and_return(CHRONY_CONF.dup)
55
+ allow(File).to receive(:write)
56
+
57
+ chronyd_service = double
58
+ expect(LinuxAdmin::Service).to receive(:new).with("chronyd").and_return(chronyd_service)
59
+ expect(chronyd_service).to receive(:running?).and_return false
60
+ expect(chronyd_service).not_to receive(:restart)
38
61
  subject.add_servers("baz.example.net", "foo.bar.example.com")
39
62
  end
40
63
  end
data/spec/hosts_spec.rb CHANGED
@@ -32,6 +32,35 @@ describe LinuxAdmin::Hosts do
32
32
  end
33
33
  end
34
34
 
35
+ describe "#set_loopback_hostname" do
36
+ etc_hosts_v6_loopback = <<-EOT
37
+
38
+ #Some Comment
39
+ ::1\tlocalhost localhost.localdomain # with a comment
40
+ 127.0.0.1\tlocalhost localhost.localdomain # with a comment
41
+ 127.0.1.1 my.domain.local
42
+ EOT
43
+
44
+ before do
45
+ allow(File).to receive(:read).and_return(etc_hosts_v6_loopback)
46
+ @instance_v6_loopback = LinuxAdmin::Hosts.new
47
+ end
48
+
49
+ it "adds the hostname to the start of the hosts list for the loopback addresses" do
50
+ expected_hash = [{:blank => true},
51
+ {:comment => "Some Comment"},
52
+ {:address => "::1",
53
+ :hosts => ["examplehost.example.com", "localhost", "localhost.localdomain"],
54
+ :comment => "with a comment"},
55
+ {:address => "127.0.0.1",
56
+ :hosts => ["examplehost.example.com", "localhost", "localhost.localdomain"],
57
+ :comment => "with a comment"},
58
+ {:address => "127.0.1.1", :hosts => ["my.domain.local"]}]
59
+ @instance_v6_loopback.set_loopback_hostname("examplehost.example.com")
60
+ expect(@instance_v6_loopback.parsed_file).to eq(expected_hash)
61
+ end
62
+ end
63
+
35
64
  describe "#set_canonical_hostname" do
36
65
  it "removes an existing entry and creates a new one" do
37
66
  expected_hash = [{:blank => true},
@@ -20,6 +20,12 @@ eos
20
20
  @mount_out2 = <<eos
21
21
  cgroup on /sys/fs/cgroup/perf_event type cgroup (rw,nosuid,nodev,noexec,relatime,perf_event)
22
22
  systemd-1 on /proc/sys/fs/binfmt_misc type autofs (rw,relatime,fd=26,pgrp=1,timeout=300,minproto=5,maxproto=5,direct)
23
+ eos
24
+
25
+ @mount_out3 = <<eos
26
+ /dev/mapper/vg_data-lv_pg on /var/opt/rh/rh-postgresql95/lib/pgsql type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
27
+ /dev/foo on /tmp type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
28
+ /dev/foo on /home type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
23
29
  eos
24
30
  end
25
31
 
@@ -67,6 +73,20 @@ eos
67
73
  end
68
74
  end
69
75
 
76
+ describe "#discover_mount_point" do
77
+ it "sets the correct mountpoint when the path is mounted" do
78
+ expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out3))
79
+ @mountable.discover_mount_point
80
+ expect(@mountable.mount_point).to eq("/tmp")
81
+ end
82
+
83
+ it "sets mount_point to nil when the path is not mounted" do
84
+ expect(LinuxAdmin::Common).to receive(:run!).and_return(double(:output => @mount_out1))
85
+ @mountable.discover_mount_point
86
+ expect(@mountable.mount_point).to be_nil
87
+ end
88
+ end
89
+
70
90
  describe "#format_to" do
71
91
  it "uses mke2fs" do
72
92
  expect(LinuxAdmin::Common).to receive(:run!)
data/spec/ssh_spec.rb CHANGED
@@ -42,12 +42,12 @@ sV1Tr/acrE0aWBkD9RYrR2/UwG1zfXuIJeufdWf8c0SY3X6J7jJN
42
42
  end
43
43
 
44
44
  it "should preform command using private key" do
45
- expect(Net::SSH).to receive(:start).with("127.0.0.1", "root", :paranoid => false, :key_data => [@example_ssh_key]).and_return(true)
45
+ expect(Net::SSH).to receive(:start).with("127.0.0.1", "root", :paranoid => false, :number_of_password_prompts => 0, :key_data => [@example_ssh_key]).and_return(true)
46
46
  LinuxAdmin::SSH.new("127.0.0.1", "root", @example_ssh_key).perform_commands(%w("ls", "pwd"))
47
47
  end
48
48
 
49
49
  it "should preform command using password" do
50
- expect(Net::SSH).to receive(:start).with("127.0.0.1", "root", :paranoid => false, :password => "password").and_return(true)
50
+ expect(Net::SSH).to receive(:start).with("127.0.0.1", "root", :paranoid => false, :number_of_password_prompts => 0, :password => "password").and_return(true)
51
51
  LinuxAdmin::SSH.new("127.0.0.1", "root", nil, "password").perform_commands(%w("ls", "pwd"))
52
52
  end
53
53
  end
@@ -30,6 +30,38 @@ describe LinuxAdmin::TimeDate do
30
30
  end
31
31
  end
32
32
 
33
+ describe ".timezones" do
34
+ let(:timezones) do
35
+ <<-EOS
36
+ Africa/Bangui
37
+ Africa/Banjul
38
+ Africa/Bissau
39
+ Africa/Blantyre
40
+ Africa/Brazzaville
41
+ Africa/Bujumbura
42
+ Africa/Cairo
43
+ America/Havana
44
+ America/Hermosillo
45
+ America/Indiana/Indianapolis
46
+ America/Indiana/Knox
47
+ America/Argentina/San_Juan
48
+ America/Argentina/San_Luis
49
+ America/Argentina/Tucuman
50
+ America/Argentina/Ushuaia
51
+ EOS
52
+ end
53
+
54
+ it "returns the correct list" do
55
+ awesome_spawn_args = [
56
+ RUN_COMMAND,
57
+ :params => ["list-timezones"]
58
+ ]
59
+ result = AwesomeSpawn::CommandResult.new("", timezones, "", 0)
60
+ expect(AwesomeSpawn).to receive(:run!).with(*awesome_spawn_args).and_return(result)
61
+ expect(described_class.timezones).to eq(timezones.split("\n"))
62
+ end
63
+ end
64
+
33
65
  describe ".system_time=" do
34
66
  it "sets the time" do
35
67
  time = Time.new(2015, 1, 1, 1, 1, 1)
data/spec/yum_spec.rb CHANGED
@@ -84,7 +84,7 @@ describe LinuxAdmin::Yum do
84
84
  end
85
85
 
86
86
  it "other exit code" do
87
- allow(LinuxAdmin::Common).to receive_messages(:run => double(:exit_status => 255))
87
+ allow(LinuxAdmin::Common).to receive_messages(:run => double(:exit_status => 255, :error => 'test'))
88
88
  expect { described_class.updates_available? }.to raise_error(RuntimeError)
89
89
  end
90
90
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Dunne
@@ -15,10 +15,12 @@ authors:
15
15
  - Yuri Rudman
16
16
  - Oleg Barenboim
17
17
  - Alon Goldboim
18
+ - Šimon Lukašík
19
+ - Joe VLcek
18
20
  autorequire:
19
21
  bindir: bin
20
22
  cert_chain: []
21
- date: 2016-07-25 00:00:00.000000000 Z
23
+ date: 2016-10-31 00:00:00.000000000 Z
22
24
  dependencies:
23
25
  - !ruby/object:Gem::Dependency
24
26
  name: bundler
@@ -191,6 +193,8 @@ email:
191
193
  - yrudman@redhat.com
192
194
  - chessbyte@gmail.com
193
195
  - alongoldboim@gmail.com
196
+ - isimluk@fedoraproject.org
197
+ - jvlcek@redhat.com
194
198
  executables: []
195
199
  extensions: []
196
200
  extra_rdoc_files: []