示例#1
0
    def test_modify_calls_omshell_correctly(self):
        server_address = factory.make_string()
        shared_key = factory.make_string()
        ip_address = factory.make_ip_address(ipv6=self.ipv6)
        mac_address = factory.make_mac_address()
        shell = Omshell(server_address, shared_key, ipv6=self.ipv6)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, b"hardware-type"))
        shell._run = recorder

        shell.modify(ip_address, mac_address)

        expected_script = dedent("""\
            server {server}
            key omapi_key {key}
            connect
            new host
            set name = "{name}"
            open
            set ip-address = {ip}
            set hardware-address = {mac}
            set hardware-type = 1
            update
            """)
        expected_script = expected_script.format(
            server=server_address, key=shared_key, ip=ip_address,
            mac=mac_address, name=mac_address.replace(':', '-'))

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual(
            [1, (expected_script.encode("utf-8"),)],
            [recorder.call_count, recorder.extract_args()[0]])
示例#2
0
 def test_restart_dhcp_server_sends_command(self):
     recorder = FakeMethod()
     self.patch(tasks, 'call_and_check', recorder)
     restart_dhcp_server()
     self.assertEqual(
         (1, (['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'],)),
         (recorder.call_count, recorder.extract_args()[0]))
示例#3
0
    def test_remove_calls_omshell_correctly(self):
        server_address = factory.getRandomString()
        shared_key = factory.getRandomString()
        ip_address = factory.getRandomIPAddress()
        shell = Omshell(server_address, shared_key)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, "thing1\nthing2\nobj: <null>"))
        shell._run = recorder

        shell.remove(ip_address)

        expected_script = dedent("""\
            server {server}
            key omapi_key {key}
            connect
            new host
            set name = "{ip}"
            open
            remove
            """)
        expected_script = expected_script.format(server=server_address,
                                                 key=shared_key,
                                                 ip=ip_address)

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual([(expected_script, )], recorder.extract_args())
示例#4
0
    def test_remove_calls_omshell_correctly(self):
        server_address = factory.make_string()
        shared_key = factory.make_string()
        mac_address = factory.make_mac_address()
        shell = Omshell(server_address, shared_key, ipv6=self.ipv6)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, b"thing1\nthing2\nobj: <null>"))
        shell._run = recorder

        shell.remove(mac_address)

        expected_script = dedent("""\
            server {server}
            port {port}
            key omapi_key {key}
            connect
            new host
            set name = "{mac}"
            open
            remove
            """).format(
            server=server_address,
            port=self.port,
            key=shared_key,
            mac=mac_address.replace(":", "-"),
        )
        expected_results = (expected_script.encode("utf-8"), )

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual([expected_results], recorder.extract_args())
示例#5
0
    def test_try_connection_calls_omshell_correctly(self):
        server_address = factory.make_string()
        shell = Omshell(server_address, "", ipv6=self.ipv6)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, b"obj: <null>"))
        shell._run = recorder

        shell.try_connection()

        expected_script = dedent("""\
            server {server}
            port {port}
            connect
            """)
        expected_script = expected_script.format(server=server_address,
                                                 port=self.port)

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual(
            [1, (expected_script.encode("utf-8"), )],
            [recorder.call_count,
             recorder.extract_args()[0]],
        )
示例#6
0
 def test_restart_dhcp_server_sends_command(self):
     recorder = FakeMethod()
     self.patch(tasks, 'call_and_check', recorder)
     restart_dhcp_server()
     self.assertEqual(
         (1, (['sudo', '-n', 'service', 'maas-dhcp-server', 'restart'], )),
         (recorder.call_count, recorder.extract_args()[0]))
示例#7
0
    def test_create_calls_omshell_correctly(self):
        server_address = factory.getRandomString()
        shared_key = factory.getRandomString()
        ip_address = factory.getRandomIPAddress()
        mac_address = factory.getRandomMACAddress()
        shell = Omshell(server_address, shared_key)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, "hardware-type"))
        shell._run = recorder

        shell.create(ip_address, mac_address)

        expected_script = dedent("""\
            server {server}
            key omapi_key {key}
            connect
            new host
            set ip-address = {ip}
            set hardware-address = {mac}
            set hardware-type = 1
            set name = "{ip}"
            create
            """)
        expected_script = expected_script.format(server=server_address,
                                                 key=shared_key,
                                                 ip=ip_address,
                                                 mac=mac_address)

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual([1, (expected_script, )],
                         [recorder.call_count,
                          recorder.extract_args()[0]])
示例#8
0
 def test_start_up_calls_write_full_dns_config(self):
     recorder = FakeMethod()
     self.patch(start_up, 'write_full_dns_config', recorder)
     start_up.start_up()
     self.assertEqual(
         (1, [()]),
         (recorder.call_count, recorder.extract_args()))
示例#9
0
 def test_start_up_calls_setup_maas_avahi_service(self):
     recorder = FakeMethod()
     self.patch(start_up, 'setup_maas_avahi_service', recorder)
     start_up.start_up()
     self.assertEqual(
         (1, [()]),
         (recorder.call_count, recorder.extract_args()))
示例#10
0
    def test_create_calls_omshell_correctly(self):
        server_address = factory.getRandomString()
        shared_key = factory.getRandomString()
        ip_address = factory.getRandomIPAddress()
        mac_address = factory.getRandomMACAddress()
        shell = Omshell(server_address, shared_key)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, "hardware-type"))
        shell._run = recorder

        shell.create(ip_address, mac_address)

        expected_args = (dedent("""\
            server {server}
            key omapi_key {key}
            connect
            new host
            set ip-address = {ip}
            set hardware-address = {mac}
            set hardware-type = 1
            set name = "{ip}"
            create
            """).format(
                server=server_address,
                key=shared_key,
                ip=ip_address,
                mac=mac_address),)

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual(
            [1, expected_args],
            [recorder.call_count, recorder.extract_args()[0]])
示例#11
0
    def test_remove_calls_omshell_correctly(self):
        server_address = factory.getRandomString()
        shared_key = factory.getRandomString()
        ip_address = factory.getRandomIPAddress()
        shell = Omshell(server_address, shared_key)

        # Instead of calling a real omshell, we'll just record the
        # parameters passed to Popen.
        recorder = FakeMethod(result=(0, "thing1\nthing2\nobj: <null>"))
        shell._run = recorder

        shell.remove(ip_address)

        expected_args = (dedent("""\
            server {server}
            key omapi_key {key}
            connect
            new host
            set name = "{ip}"
            open
            remove
            """).format(
                server=server_address,
                key=shared_key,
                ip=ip_address),)

        # Check that the 'stdin' arg contains the correct set of
        # commands.
        self.assertEqual([expected_args], recorder.extract_args())
示例#12
0
 def test_get_dns_server_address_resolves_hostname(self):
     ip = factory.getRandomIPAddress()
     resolver = FakeMethod(result=ip)
     self.patch(server_address, 'gethostbyname', resolver)
     hostname = factory.make_hostname()
     self.patch_DEFAULT_MAAS_URL_with_random_values(hostname=hostname)
     self.assertEqual(
         (ip, [(hostname, )]),
         (dns.get_dns_server_address(), resolver.extract_args()))
示例#13
0
 def test_get_maas_facing_server_address_resolves_hostname(self):
     ip = factory.getRandomIPAddress()
     resolver = FakeMethod(result=ip)
     self.patch(server_address, 'gethostbyname', resolver)
     hostname = self.make_hostname()
     self.set_DEFAULT_MAAS_URL(hostname=hostname)
     self.assertEqual(
         (ip, [(hostname, )]),
         (get_maas_facing_server_address(), resolver.extract_args()))
示例#14
0
 def test_get_maas_facing_server_address_resolves_hostname(self):
     ip = factory.getRandomIPAddress()
     resolver = FakeMethod(result=ip)
     self.patch(server_address, 'gethostbyname', resolver)
     hostname = self.make_hostname()
     self.set_DEFAULT_MAAS_URL(hostname=hostname)
     self.assertEqual(
         (ip, [(hostname, )]),
         (get_maas_facing_server_address(), resolver.extract_args()))
示例#15
0
 def test_get_dns_server_address_uses_nodegroup_maas_url(self):
     ip = factory.getRandomIPAddress()
     resolver = FakeMethod(result=ip)
     self.patch(server_address, 'gethostbyname', resolver)
     hostname = factory.make_hostname()
     maas_url = 'http://%s' % hostname
     nodegroup = factory.make_node_group(maas_url=maas_url)
     self.assertEqual(
         (ip, [(hostname, )]),
         (dns.get_dns_server_address(nodegroup), resolver.extract_args()))
示例#16
0
    def test_write_full_dns_passes_reload_retry_parameter(self):
        self.patch(settings, 'DNS_CONNECT', True)
        recorder = FakeMethod()
        self.create_managed_nodegroup()

        @task
        def recorder_task(*args, **kwargs):
            return recorder(*args, **kwargs)

        self.patch(tasks, 'rndc_command', recorder_task)
        dns.write_full_dns_config(reload_retry=True)
        self.assertEqual(([(['reload'], True)]), recorder.extract_args())
示例#17
0
 def test_start_up_calls_setup_maas_avahi_service(self):
     recorder = FakeMethod()
     self.patch(start_up, 'setup_maas_avahi_service', recorder)
     start_up.start_up()
     self.assertEqual((1, [()]),
                      (recorder.call_count, recorder.extract_args()))
示例#18
0
 def test_extract_args_returns_just_call_args(self):
     stub = FakeMethod()
     stub(1, 2, 3, x=12)
     self.assertItemsEqual([(1, 2, 3)], stub.extract_args())
示例#19
0
 def test_start_up_calls_write_full_dns_config(self):
     recorder = FakeMethod()
     self.patch(start_up, 'write_full_dns_config', recorder)
     start_up.start_up()
     self.assertEqual((1, [()]),
                      (recorder.call_count, recorder.extract_args()))