예제 #1
0
 def test_add_dhcp_host_maps_does_nothing_if_not_managing_dhcp(self):
     self.patch(Omshell, 'create', FakeMethod())
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     self.assertEqual([], Omshell.create.extract_args())
예제 #2
0
 def test_fires_tasks_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group()
     task = self.patch(nodegroup_module, 'add_new_dhcp_host_map')
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     args, kwargs = task.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
예제 #3
0
 def test_update_leases_leaves_other_nodegroups_alone(self):
     innocent_nodegroup = factory.make_node_group()
     innocent_lease = factory.make_dhcp_lease(nodegroup=innocent_nodegroup)
     DHCPLease.objects.update_leases(
         factory.make_node_group(), factory.make_random_leases())
     self.assertItemsEqual(
         [innocent_lease], get_leases(innocent_nodegroup))
예제 #4
0
 def test_add_dhcp_host_maps_does_nothing_if_not_managing_dhcp(self):
     self.patch(Omshell, 'create', FakeMethod())
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     self.assertEqual([], Omshell.create.extract_args())
예제 #5
0
 def test_add_dhcp_host_maps_adds_maps_if_managing_dhcp(self):
     self.patch(Omshell, 'create', FakeMethod())
     nodegroup = factory.make_node_group()
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     self.assertEqual([(leases.keys()[0], leases.values()[0])],
                      Omshell.create.extract_args())
예제 #6
0
 def test_fires_tasks_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group()
     task = self.patch(nodegroup_module, 'add_new_dhcp_host_map')
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     args, kwargs = task.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
예제 #7
0
 def test_add_dhcp_host_maps_adds_maps_if_managing_dhcp(self):
     self.patch(Omshell, 'create', FakeMethod())
     nodegroup = factory.make_node_group()
     leases = factory.make_random_leases()
     nodegroup.add_dhcp_host_maps(leases)
     self.assertEqual(
         [(leases.keys()[0], leases.values()[0])],
         Omshell.create.extract_args())
예제 #8
0
 def test_update_leases_does_not_add_old_leases(self):
     self.patch(Omshell, 'create')
     nodegroup = factory.make_node_group()
     client = make_worker_client(nodegroup)
     self.patch(tasks, 'add_new_dhcp_host_map', FakeMethod())
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]), {
             'op': 'update_leases',
             'leases': json.dumps(factory.make_random_leases()),
         })
     self.assertEqual((httplib.OK, "Leases updated."),
                      (response.status_code, response.content))
     self.assertEqual([], tasks.add_new_dhcp_host_map.calls)
예제 #9
0
 def test_update_leases_adds_new_leases_on_worker(self):
     nodegroup = factory.make_node_group()
     client = make_worker_client(nodegroup)
     self.patch(Omshell, 'create', FakeMethod())
     new_leases = factory.make_random_leases()
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]), {
             'op': 'update_leases',
             'leases': json.dumps(new_leases),
         })
     self.assertEqual((httplib.OK, "Leases updated."),
                      (response.status_code, response.content))
     self.assertEqual([(new_leases.keys()[0], new_leases.values()[0])],
                      Omshell.create.extract_args())
예제 #10
0
    def test_update_leases_returns_new_leases(self):
        nodegroup = factory.make_node_group()
        obsolete_lease = factory.make_dhcp_lease(nodegroup=nodegroup)
        ignore_unused(obsolete_lease)
        remaining_lease = factory.make_dhcp_lease(nodegroup=nodegroup)
        new_lease = factory.make_random_leases()

        surviving_leases = {
            remaining_lease.ip: remaining_lease.mac,
            new_lease.keys()[0]: new_lease.values()[0],
        }

        self.assertItemsEqual(
            new_lease.keys(),
            DHCPLease.objects.update_leases(nodegroup, surviving_leases))
예제 #11
0
 def test_update_leases_does_not_add_old_leases(self):
     self.patch(Omshell, 'create')
     nodegroup = factory.make_node_group()
     client = make_worker_client(nodegroup)
     self.patch(tasks, 'add_new_dhcp_host_map', FakeMethod())
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]),
         {
             'op': 'update_leases',
             'leases': json.dumps(factory.make_random_leases()),
         })
     self.assertEqual(
         (httplib.OK, "Leases updated."),
         (response.status_code, response.content))
     self.assertEqual([], tasks.add_new_dhcp_host_map.calls)
예제 #12
0
 def test_update_leases_stores_leases(self):
     self.patch(Omshell, 'create')
     nodegroup = factory.make_node_group()
     lease = factory.make_random_leases()
     client = make_worker_client(nodegroup)
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]), {
             'op': 'update_leases',
             'leases': json.dumps(lease),
         })
     self.assertEqual((httplib.OK, "Leases updated."),
                      (response.status_code, response.content))
     self.assertItemsEqual(lease.keys(), [
         dhcplease.ip
         for dhcplease in DHCPLease.objects.filter(nodegroup=nodegroup)
     ])
예제 #13
0
 def test_worker_calls_update_leases(self):
     # In bug 1041158, the worker's upload_leases task tried to call
     # the update_leases API at the wrong URL path.  It has the right
     # path now.
     self.useFixture(
         EnvironmentVariableFixture("MAAS_URL", settings.DEFAULT_MAAS_URL))
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
     refresh_worker(nodegroup)
     self.patch(MAASClient, 'post', Mock())
     leases = factory.make_random_leases()
     send_leases(leases)
     nodegroup_path = reverse(
         'nodegroup_handler', args=[nodegroup.uuid])
     nodegroup_path = nodegroup_path.decode('ascii').lstrip('/')
     MAASClient.post.assert_called_once_with(
         nodegroup_path, 'update_leases', leases=json.dumps(leases))
예제 #14
0
 def test_worker_calls_update_leases(self):
     # In bug 1041158, the worker's upload_leases task tried to call
     # the update_leases API at the wrong URL path.  It has the right
     # path now.
     self.useFixture(
         EnvironmentVariableFixture("MAAS_URL", settings.DEFAULT_MAAS_URL))
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
     refresh_worker(nodegroup)
     self.patch(MAASClient, 'post', Mock())
     leases = factory.make_random_leases()
     send_leases(leases)
     nodegroup_path = reverse('nodegroup_handler', args=[nodegroup.uuid])
     nodegroup_path = nodegroup_path.decode('ascii').lstrip('/')
     MAASClient.post.assert_called_once_with(nodegroup_path,
                                             'update_leases',
                                             leases=json.dumps(leases))
예제 #15
0
 def test_update_leases_adds_new_leases_on_worker(self):
     nodegroup = factory.make_node_group()
     client = make_worker_client(nodegroup)
     self.patch(Omshell, 'create', FakeMethod())
     new_leases = factory.make_random_leases()
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]),
         {
             'op': 'update_leases',
             'leases': json.dumps(new_leases),
         })
     self.assertEqual(
         (httplib.OK, "Leases updated."),
         (response.status_code, response.content))
     self.assertEqual(
         [(new_leases.keys()[0], new_leases.values()[0])],
         Omshell.create.extract_args())
예제 #16
0
 def test_update_leases_stores_leases(self):
     self.patch(Omshell, 'create')
     nodegroup = factory.make_node_group()
     lease = factory.make_random_leases()
     client = make_worker_client(nodegroup)
     response = client.post(
         reverse('nodegroup_handler', args=[nodegroup.uuid]),
         {
             'op': 'update_leases',
             'leases': json.dumps(lease),
         })
     self.assertEqual(
         (httplib.OK, "Leases updated."),
         (response.status_code, response.content))
     self.assertItemsEqual(
         lease.keys(), [
             dhcplease.ip
             for dhcplease in DHCPLease.objects.filter(nodegroup=nodegroup)
         ])
예제 #17
0
 def test_update_leases_creates_new_lease(self):
     nodegroup = factory.make_node_group()
     lease = factory.make_random_leases()
     DHCPLease.objects.update_leases(nodegroup, lease)
     self.assertEqual(lease, map_leases(nodegroup))
예제 #18
0
 def test_update_leases_updates_dns_zone(self):
     self.patch(dns, 'change_dns_zones')
     nodegroup = factory.make_node_group()
     DHCPLease.objects.update_leases(
         nodegroup, factory.make_random_leases())
     dns.change_dns_zones.assert_called_once_with([nodegroup])