Esempio n. 1
0
 def test__adds_tcp_stop(self):
     cidr = factory.make_ipv4_network()
     config.write_config([cidr])
     matcher = Contains(':inputname, isequal, "imtcp" stop')
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=matcher))
Esempio n. 2
0
 def test_udp_and_tcp(self):
     config.write_config(False)
     matcher_one = Contains('input(type="imtcp" port="5247")')
     matcher_two = Contains('input(type="imudp" port="5247")')
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=MatchesAll(matcher_one, matcher_two)),
     )
Esempio n. 3
0
 def test_snappy_root_user_group_no_drop(self):
     self.patch(snappy, "running_in_snap").return_value = True
     config.write_config(False)
     matchers = [Contains("$FileOwner root"), Contains("$FileGroup root")]
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=MatchesAll(*matchers)),
     )
Esempio n. 4
0
 def test_udp_and_tcp_both_use_different_port(self):
     port = factory.pick_port()
     config.write_config(False, port=port)
     matcher_one = Contains('input(type="imtcp" port="%d")' % port)
     matcher_two = Contains('input(type="imudp" port="%d")' % port)
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=MatchesAll(matcher_one, matcher_two)),
     )
Esempio n. 5
0
 def test_write_local(self):
     config.write_config(True)
     matcher_one = Contains(
         ':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist')
     matcher_two = Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot')
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=MatchesAll(matcher_one, matcher_two)),
     )
Esempio n. 6
0
 def test__packaging_maas_user_group_with_drop(self):
     config.write_config(False)
     matchers = [
         Contains('$FileOwner maas'),
         Contains('$FileGroup maas'),
         Contains('$PrivDropToUser maas'),
         Contains('$PrivDropToGroup maas'),
     ]
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(matcher=MatchesAll(*matchers)))
Esempio n. 7
0
 def _configure(self, configuration):
     """Update the syslog configuration for the rack."""
     # Convert the frozenset to a dictionary before constructing the
     # dictionary that `syslog_config.write_config` expects. This ensures
     # that only unique regions are included in the forwarders.
     forwarders = [
         {"name": name, "ip": ip}
         for name, ip in dict(configuration.forwarders).items()
     ]
     syslog_config.write_config(
         False, forwarders=forwarders, port=configuration.port
     )
Esempio n. 8
0
 def test_forwarders_diff_port(self):
     port = factory.pick_port()
     forwarders = [{
         "ip": factory.make_ip_address(),
         "name": factory.make_name("name"),
     } for _ in range(3)]
     config.write_config(False, forwarders, port=port)
     with self.syslog_path.open() as syslog_file:
         lines = [line.strip() for line in syslog_file.readlines()]
         for host in forwarders:
             self.assertLinesContain('target="%s"' % host["ip"], lines)
             self.assertLinesContain('port="%d"' % port, lines)
Esempio n. 9
0
 def test_forwarders(self):
     forwarders = [{
         "ip": factory.make_ip_address(),
         "name": factory.make_name("name"),
     } for _ in range(3)]
     config.write_config(False, forwarders)
     with self.syslog_path.open() as syslog_file:
         lines = [line.strip() for line in syslog_file.readlines()]
         for host in forwarders:
             self.assertLinesContain('target="%s"' % host["ip"], lines)
             self.assertLinesContain('queue.filename="%s"' % host["name"],
                                     lines)
Esempio n. 10
0
 def test__no_write_local(self):
     config.write_config(False)
     matcher_one = Not(
         Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist'))
     matcher_two = Not(
         Contains(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot'))
     # maas.log is still local when no write local.
     matcher_three = Contains(':syslogtag, contains, "maas"')
     self.assertThat(
         "%s/%s" % (self.tmpdir, config.MAAS_SYSLOG_CONF_NAME),
         FileContains(
             matcher=MatchesAll(matcher_one, matcher_two, matcher_three)))
Esempio n. 11
0
 def test_write_local_and_forwarders(self):
     forwarders = [{
         "ip": factory.make_ip_address(),
         "name": factory.make_name("name"),
     } for _ in range(3)]
     config.write_config(True, forwarders)
     with self.syslog_path.open() as syslog_file:
         lines = [line.strip() for line in syslog_file.readlines()]
         self.assertIn(':fromhost-ip, !isequal, "127.0.0.1" ?MAASenlist',
                       lines)
         self.assertIn(':fromhost-ip, !isequal, "127.0.0.1" ?MAASboot',
                       lines)
         for host in forwarders:
             self.assertLinesContain('target="%s"' % host["ip"], lines)
             self.assertLinesContain('queue.filename="%s"' % host["name"],
                                     lines)