Example #1
0
 def test_refresh_workers_skips_unaccepted_cluster_controllers(self):
     self.patch(nodegroup_module, 'refresh_worker')
     for status in map_enum(NODEGROUP_STATUS).values():
         if status != NODEGROUP_STATUS.ACCEPTED:
             factory.make_node_group(status=status)
     NodeGroup.objects.refresh_workers()
     self.assertEqual(0, nodegroup_module.refresh_worker.call_count)
Example #2
0
 def test_find_nodegroup_errors_if_multiple_matches(self):
     self.patch(nodegroupinterface, "MINIMUM_NETMASK_BITS", 1)
     factory.make_node_group(network=IPNetwork("10/8"))
     factory.make_node_group(network=IPNetwork("10.1.1/24"))
     self.assertRaises(
         NodeGroup.MultipleObjectsReturned,
         find_nodegroup, get_request('10.1.1.2'))
Example #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))
Example #4
0
 def test_refresh_workers_skips_unaccepted_cluster_controllers(self):
     self.patch(nodegroup_module, 'refresh_worker')
     for status in map_enum(NODEGROUP_STATUS).values():
         if status != NODEGROUP_STATUS.ACCEPTED:
             factory.make_node_group(status=status)
     NodeGroup.objects.refresh_workers()
     self.assertEqual(0, nodegroup_module.refresh_worker.call_count)
Example #5
0
 def test_created_node_has_domain_from_cluster(self):
     hostname_without_domain = factory.make_name('hostname')
     hostname_with_domain = '%s.%s' % (hostname_without_domain,
                                       factory.getRandomString())
     domain = factory.make_name('domain')
     factory.make_node_group(
         status=NODEGROUP_STATUS.ACCEPTED,
         name=domain,
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
     response = self.client.post(
         reverse('nodes_handler'), {
             'op':
             'new',
             'hostname':
             hostname_with_domain,
             'architecture':
             factory.getRandomChoice(ARCHITECTURE_CHOICES),
             'after_commissioning_action':
             (NODE_AFTER_COMMISSIONING_ACTION.DEFAULT),
             'mac_addresses': [factory.getRandomMACAddress()],
         })
     self.assertEqual(httplib.OK, response.status_code, response.content)
     parsed_result = json.loads(response.content)
     expected_hostname = '%s.%s' % (hostname_without_domain, domain)
     self.assertEqual(expected_hostname, parsed_result.get('hostname'))
Example #6
0
 def test_find_nodegroup_looks_up_only_configured_interfaces(self):
     network = IPNetwork("192.168.41.0/24")
     factory.make_node_group(
         network=network,
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED)
     ip = factory.getRandomIPInNetwork(network)
     self.assertIsNone(find_nodegroup(get_request(ip)))
Example #7
0
 def test_get_managed_interface_does_not_return_unrelated_interface(self):
     nodegroup = factory.make_node_group()
     # Create another nodegroup with a managed interface.
     factory.make_node_group()
     interface = nodegroup.nodegroupinterface_set.all()[0]
     interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
     interface.save()
     self.assertIsNone(nodegroup.get_managed_interface())
Example #8
0
 def test_get_managed_interface_does_not_return_unrelated_interface(self):
     nodegroup = factory.make_node_group()
     # Create another nodegroup with a managed interface.
     factory.make_node_group()
     interface = nodegroup.nodegroupinterface_set.all()[0]
     interface.management = NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED
     interface.save()
     self.assertIsNone(nodegroup.get_managed_interface())
Example #9
0
 def test_more_than_1_unmanaged_interface(self):
     nodegroup1 = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(
         nodegroup1, find_nodegroup(get_request('192.168.41.199')))
Example #10
0
 def test_more_than_1_unmanaged_interface(self):
     nodegroup1 = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/24"))
     self.assertEqual(nodegroup1,
                      find_nodegroup(get_request('192.168.41.199')))
Example #11
0
 def test_node_list_lists_nodes_from_different_nodegroups(self):
     # Bug 1084443.
     nodegroup1 = factory.make_node_group()
     nodegroup2 = factory.make_node_group()
     factory.make_node(nodegroup=nodegroup1)
     factory.make_node(nodegroup=nodegroup2)
     factory.make_node(nodegroup=nodegroup2)
     response = self.client.get(reverse('node-list'))
     self.assertEqual(httplib.OK, response.status_code)
Example #12
0
 def test_AdminForm_does_not_permit_nodegroup_change(self):
     # We had to make Node.nodegroup editable to get Django to
     # validate it as non-blankable, but that doesn't mean that we
     # actually want to allow people to edit it through API or UI.
     old_nodegroup = factory.make_node_group()
     node = factory.make_node(nodegroup=old_nodegroup)
     new_nodegroup = factory.make_node_group()
     form = AdminNodeForm(data={'nodegroup': new_nodegroup}, instance=node)
     self.assertRaises(ValueError, form.save)
Example #13
0
 def test_report_boot_images_ignores_non_accepted_groups(self):
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
     factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     factory.make_node_group(status=NODEGROUP_STATUS.REJECTED)
     recorder = self.patch(api, 'register_persistent_error')
     client = make_worker_client(nodegroup)
     image = make_boot_image_params()
     response = self.report_images(nodegroup, [image], client=client)
     self.assertEqual(httplib.OK, response.status_code)
     self.assertEqual(0, recorder.call_count)
Example #14
0
 def test_leaves_nodegroup_alone_if_unset_on_existing_node(self):
     # Selecting a node group for a node is only supported on new
     # nodes.  You can't change it later.
     original_nodegroup = factory.make_node_group()
     node = factory.make_node(nodegroup=original_nodegroup)
     factory.make_node_group(network=IPNetwork("192.168.1.0/24"))
     form = NodeWithMACAddressesForm(
         self.make_params(nodegroup='192.168.1.0'), instance=node)
     form.save()
     self.assertEqual(original_nodegroup, reload_object(node).nodegroup)
Example #15
0
 def test_report_boot_images_ignores_non_accepted_groups(self):
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
     factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     factory.make_node_group(status=NODEGROUP_STATUS.REJECTED)
     recorder = self.patch(api, 'register_persistent_error')
     client = make_worker_client(nodegroup)
     image = make_boot_image_params()
     response = self.report_images(nodegroup, [image], client=client)
     self.assertEqual(httplib.OK, response.status_code)
     self.assertEqual(0, recorder.call_count)
Example #16
0
 def test_settings_rejects_all_pending_nodegroups_POST(self):
     nodegroups = {
         factory.make_node_group(status=NODEGROUP_STATUS.PENDING),
         factory.make_node_group(status=NODEGROUP_STATUS.PENDING),
     }
     response = self.client.post(
         reverse('settings'), {'mass_reject_submit': 1})
     self.assertEqual(httplib.FOUND, response.status_code)
     self.assertEqual(
         [reload_object(nodegroup).status for nodegroup in nodegroups],
         [NODEGROUP_STATUS.REJECTED] * 2)
Example #17
0
 def test_1_managed_interface_and_1_unmanaged(self):
     # The managed nodegroup is chosen in preference to the unmanaged
     # nodegroup.
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     self.assertEqual(nodegroup,
                      find_nodegroup(get_request('192.168.41.199')))
Example #18
0
 def test_1_managed_interface_and_1_unmanaged(self):
     # The managed nodegroup is chosen in preference to the unmanaged
     # nodegroup.
     nodegroup = factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.UNMANAGED,
         network=IPNetwork("192.168.41.0/16"))
     self.assertEqual(
         nodegroup, find_nodegroup(get_request('192.168.41.199')))
Example #19
0
 def test_anonymous_get_enlist_preseed_detects_request_origin(self):
     ng_url = 'http://%s' % factory.make_name('host')
     network = IPNetwork("10.1.1/24")
     ip = factory.getRandomIPInNetwork(network)
     factory.make_node_group(maas_url=ng_url, network=network)
     anon_enlist_preseed_url = reverse('metadata-enlist-preseed',
                                       args=['latest'])
     response = self.client.get(anon_enlist_preseed_url,
                                {'op': 'get_enlist_preseed'},
                                REMOTE_ADDR=ip)
     self.assertThat(response.content, Contains(ng_url))
Example #20
0
 def test_anonymous_get_enlist_preseed_detects_request_origin(self):
     ng_url = 'http://%s' % factory.make_name('host')
     network = IPNetwork("10.1.1/24")
     ip = factory.getRandomIPInNetwork(network)
     factory.make_node_group(maas_url=ng_url, network=network)
     anon_enlist_preseed_url = reverse(
         'metadata-enlist-preseed', args=['latest'])
     response = self.client.get(
         anon_enlist_preseed_url, {'op': 'get_enlist_preseed'},
         REMOTE_ADDR=ip)
     self.assertThat(response.content, Contains(ng_url))
Example #21
0
 def test_settings_rejects_all_pending_nodegroups_POST(self):
     nodegroups = {
         factory.make_node_group(status=NODEGROUP_STATUS.PENDING),
         factory.make_node_group(status=NODEGROUP_STATUS.PENDING),
     }
     response = self.client.post(
         reverse('settings'), {'mass_reject_submit': 1})
     self.assertEqual(httplib.FOUND, response.status_code)
     self.assertEqual(
         [reload_object(nodegroup).status for nodegroup in nodegroups],
         [NODEGROUP_STATUS.REJECTED] * 2)
Example #22
0
 def test_get_hostname_ip_mapping_considers_given_nodegroup(self):
     nodegroup = factory.make_node_group()
     node = factory.make_node(
         nodegroup=nodegroup)
     mac = factory.make_mac_address(node=node)
     factory.make_dhcp_lease(
         nodegroup=nodegroup, mac=mac.mac_address)
     another_nodegroup = factory.make_node_group()
     mapping = DHCPLease.objects.get_hostname_ip_mapping(
         another_nodegroup)
     self.assertEqual({}, mapping)
Example #23
0
 def test_get_userdata_detects_request_origin(self):
     nodegroup_url = 'http://%s' % factory.make_name('host')
     maas_url = 'http://%s' % factory.make_hostname()
     self.patch(settings, 'DEFAULT_MAAS_URL', maas_url)
     network = IPNetwork("10.1.1/24")
     ip = factory.getRandomIPInNetwork(network)
     factory.make_node_group(maas_url=nodegroup_url, network=network)
     url = reverse('enlist-metadata-user-data', args=['latest'])
     response = self.client.get(url, REMOTE_ADDR=ip)
     self.assertThat(
         response.content,
         MatchesAll(Contains(nodegroup_url), Not(Contains(maas_url))))
Example #24
0
 def test_get_userdata_detects_request_origin(self):
     nodegroup_url = 'http://%s' % factory.make_name('host')
     maas_url = 'http://%s' % factory.make_hostname()
     self.patch(settings, 'DEFAULT_MAAS_URL', maas_url)
     network = IPNetwork("10.1.1/24")
     ip = factory.getRandomIPInNetwork(network)
     factory.make_node_group(maas_url=nodegroup_url, network=network)
     url = reverse('enlist-metadata-user-data', args=['latest'])
     response = self.client.get(url, REMOTE_ADDR=ip)
     self.assertThat(
         response.content,
         MatchesAll(Contains(nodegroup_url), Not(Contains(maas_url))))
Example #25
0
    def test_update_leases_does_not_let_worker_update_other_nodegroup(self):
        requesting_nodegroup = factory.make_node_group()
        about_nodegroup = factory.make_node_group()
        client = make_worker_client(requesting_nodegroup)

        response = client.post(
            reverse('nodegroup_handler', args=[about_nodegroup.uuid]),
            {'op': 'update_leases', 'leases': json.dumps({})})

        self.assertEqual(
            httplib.FORBIDDEN, response.status_code,
            explain_unexpected_response(httplib.FORBIDDEN, response))
Example #26
0
    def test_report_boot_images_warns_if_any_nodegroup_has_no_images(self):
        nodegroup = NodeGroup.objects.ensure_master()
        # Second nodegroup with no images.
        factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
        recorder = self.patch(api, 'register_persistent_error')
        client = make_worker_client(nodegroup)
        image = make_boot_image_params()
        response = self.report_images(nodegroup, [image], client=client)
        self.assertEqual((httplib.OK, "OK"),
                         (response.status_code, response.content))

        self.assertIn(COMPONENT.IMPORT_PXE_FILES,
                      [args[0][0] for args in recorder.call_args_list])
Example #27
0
    def test_update_leases_does_not_let_worker_update_other_nodegroup(self):
        requesting_nodegroup = factory.make_node_group()
        about_nodegroup = factory.make_node_group()
        client = make_worker_client(requesting_nodegroup)

        response = client.post(
            reverse('nodegroup_handler', args=[about_nodegroup.uuid]), {
                'op': 'update_leases',
                'leases': json.dumps({})
            })

        self.assertEqual(
            httplib.FORBIDDEN, response.status_code,
            explain_unexpected_response(httplib.FORBIDDEN, response))
Example #28
0
    def test_POST_report_download_progress_does_work_for_other_cluster(self):
        filename = factory.getRandomString()
        client = make_worker_client(factory.make_node_group())

        response = client.post(
            reverse('nodegroup_handler',
                    args=[factory.make_node_group().uuid]), {
                        'op': 'report_download_progress',
                        'filename': filename,
                    })

        self.assertEqual(
            httplib.FORBIDDEN, response.status_code,
            explain_unexpected_response(httplib.FORBIDDEN, response))
Example #29
0
 def test_settings_import_boot_images_calls_tasks(self):
     recorder = self.patch(nodegroup_module, 'import_boot_images')
     accepted_nodegroups = [
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
     ]
     response = self.client.post(
         reverse('settings'), {'import_all_boot_images': 1})
     self.assertEqual(httplib.FOUND, response.status_code)
     calls = [
         call(queue=nodegroup.work_queue, kwargs=ANY)
         for nodegroup in accepted_nodegroups
     ]
     self.assertItemsEqual(calls, recorder.apply_async.call_args_list)
Example #30
0
 def test_settings_import_boot_images_calls_tasks(self):
     recorder = self.patch(nodegroup_module, 'import_boot_images')
     accepted_nodegroups = [
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
     ]
     response = self.client.post(
         reverse('settings'), {'import_all_boot_images': 1})
     self.assertEqual(httplib.FOUND, response.status_code)
     calls = [
        call(queue=nodegroup.work_queue, kwargs=ANY)
        for nodegroup in accepted_nodegroups
     ]
     self.assertItemsEqual(calls, recorder.apply_async.call_args_list)
Example #31
0
    def test_report_boot_images_warns_if_any_nodegroup_has_no_images(self):
        nodegroup = NodeGroup.objects.ensure_master()
        # Second nodegroup with no images.
        factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
        recorder = self.patch(api, 'register_persistent_error')
        client = make_worker_client(nodegroup)
        image = make_boot_image_params()
        response = self.report_images(nodegroup, [image], client=client)
        self.assertEqual(
            (httplib.OK, "OK"),
            (response.status_code, response.content))

        self.assertIn(
            COMPONENT.IMPORT_PXE_FILES,
            [args[0][0] for args in recorder.call_args_list])
 def test_write_dns_config_writes_zone_file(self):
     dns_conf_dir = self.make_dir()
     self.patch(conf, 'DNS_CONFIG_DIR', dns_conf_dir)
     self.patch(settings, 'DNS_CONNECT', True)
     # Prevent rndc task dispatch.
     self.patch(tasks, "rndc_command")
     domain = factory.getRandomString()
     factory.make_node_group(
         name=domain,
         network=IPNetwork('192.168.0.1/24'),
         status=NODEGROUP_STATUS.ACCEPTED,
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS)
     call_command('write_dns_config')
     zone_file = os.path.join(dns_conf_dir, 'zone.%s' % domain)
     self.assertThat(zone_file, FileExists())
Example #33
0
    def test_POST_report_download_progress_does_work_for_other_cluster(self):
        filename = factory.getRandomString()
        client = make_worker_client(factory.make_node_group())

        response = client.post(
            reverse(
                'nodegroup_handler', args=[factory.make_node_group().uuid]),
            {
                'op': 'report_download_progress',
                'filename': filename,
            })

        self.assertEqual(
            httplib.FORBIDDEN, response.status_code,
            explain_unexpected_response(httplib.FORBIDDEN, response))
Example #34
0
    def test_report_boot_images_warns_if_no_images_found(self):
        nodegroup = NodeGroup.objects.ensure_master()
        factory.make_node_group()  # Second nodegroup with no images.
        recorder = self.patch(api, 'register_persistent_error')
        client = make_worker_client(nodegroup)
        response = self.report_images(nodegroup, [], client=client)
        self.assertEqual((httplib.OK, "OK"),
                         (response.status_code, response.content))

        self.assertIn(COMPONENT.IMPORT_PXE_FILES,
                      [args[0][0] for args in recorder.call_args_list])
        # Check that the persistent error message contains a link to the
        # clusters listing.
        self.assertIn("/settings/#accepted-clusters",
                      recorder.call_args_list[0][0][1])
Example #35
0
 def test_more_than_1_managed_interface(self):
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/16"))
     factory.make_node_group(
         management=NODEGROUPINTERFACE_MANAGEMENT.DHCP_AND_DNS,
         network=IPNetwork("192.168.41.0/24"))
     exception = self.assertRaises(NodeGroupMisconfiguration,
                                   find_nodegroup,
                                   get_request('192.168.41.199'))
     self.assertEqual(
         (httplib.CONFLICT, "Multiple clusters on the same network; only "
          "one cluster may manage the network of which "
          "192.168.41.199 is a member."),
         (exception.api_error, "%s" % exception))
Example #36
0
 def test_details_refuses_nonworker(self):
     log_in_as_normal_user(self.client)
     nodegroup = factory.make_node_group()
     response = self.make_details_request(self.client, nodegroup)
     self.assertEqual(
         httplib.FORBIDDEN, response.status_code,
         explain_unexpected_response(httplib.FORBIDDEN, response))
Example #37
0
 def test_POST_update_nodes_doesnt_modify_other_nodegroup_nodes(self):
     tag = factory.make_tag()
     nodegroup_mine = factory.make_node_group()
     nodegroup_theirs = factory.make_node_group()
     node_theirs = factory.make_node(nodegroup=nodegroup_theirs)
     client = make_worker_client(nodegroup_mine)
     response = client.post(
         self.get_tag_uri(tag), {
             'op': 'update_nodes',
             'add': [node_theirs.system_id],
             'nodegroup': nodegroup_mine.uuid,
         })
     self.assertEqual(httplib.OK, response.status_code)
     parsed_result = json.loads(response.content)
     self.assertEqual({'added': 0, 'removed': 0}, parsed_result)
     self.assertItemsEqual([], tag.node_set.all())
Example #38
0
 def test_import_boot_images_on_schedule_imports_images(self):
     self.patch(NodeGroup, 'import_boot_images')
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED)
     tasks.import_boot_images_on_schedule()
     self.assertEqual(
         [mock.call()],
         nodegroup.import_boot_images.mock_calls)
 def test_settings_contains_links_to_edit_and_delete_clusters(self):
     nodegroups = {
         factory.make_node_group(status=NODEGROUP_STATUS.ACCEPTED),
         factory.make_node_group(status=NODEGROUP_STATUS.PENDING),
         factory.make_node_group(status=NODEGROUP_STATUS.REJECTED),
         }
     links = get_content_links(self.client.get(reverse('settings')))
     nodegroup_edit_links = [
         reverse('cluster-edit', args=[nodegroup.uuid])
         for nodegroup in nodegroups]
     nodegroup_delete_links = [
         reverse('cluster-delete', args=[nodegroup.uuid])
         for nodegroup in nodegroups]
     self.assertThat(
         links,
         ContainsAll(nodegroup_edit_links + nodegroup_delete_links))
Example #40
0
 def test_update_leases_replaces_reassigned_ip(self):
     nodegroup = factory.make_node_group()
     ip = factory.getRandomIPAddress()
     factory.make_dhcp_lease(nodegroup=nodegroup, ip=ip)
     new_mac = factory.getRandomMACAddress()
     DHCPLease.objects.update_leases(nodegroup, {ip: new_mac})
     self.assertEqual({ip: new_mac}, map_leases(nodegroup))
Example #41
0
 def test_populate_tags_task_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group()
     tag = factory.make_tag()
     task = self.patch(populate_tags_module, 'update_node_tags')
     populate_tags(tag)
     args, kwargs = task.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
Example #42
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'])
Example #43
0
 def test_write_dhcp_config_task_routed_to_nodegroup_worker(self):
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     self.patch(settings, "DHCP_CONNECT", True)
     self.patch(dhcp, 'write_dhcp_config')
     nodegroup.accept()
     args, kwargs = dhcp.write_dhcp_config.apply_async.call_args
     self.assertEqual(nodegroup.work_queue, kwargs['queue'])
Example #44
0
 def test__mass_change_status_changes_statuses(self):
     old_status = factory.getRandomEnum(NODEGROUP_STATUS)
     nodegroup1 = factory.make_node_group(status=old_status)
     nodegroup2 = factory.make_node_group(status=old_status)
     new_status = factory.getRandomEnum(NODEGROUP_STATUS,
                                        but_not=[old_status])
     changed = NodeGroup.objects._mass_change_status(old_status, new_status)
     self.assertEqual((
         reload_object(nodegroup1).status,
         reload_object(nodegroup2).status,
         2,
     ), (
         new_status,
         new_status,
         changed,
     ))
Example #45
0
 def test_accept_all_pending_does_not_change_others(self):
     unaffected_status = factory.getRandomEnum(
         NODEGROUP_STATUS, but_not=[NODEGROUP_STATUS.PENDING])
     nodegroup = factory.make_node_group(status=unaffected_status)
     changed_count = NodeGroup.objects.accept_all_pending()
     self.assertEqual((unaffected_status, 0),
                      (reload_object(nodegroup).status, changed_count))
Example #46
0
 def test_POST_update_nodes_doesnt_modify_other_nodegroup_nodes(self):
     tag = factory.make_tag()
     nodegroup_mine = factory.make_node_group()
     nodegroup_theirs = factory.make_node_group()
     node_theirs = factory.make_node(nodegroup=nodegroup_theirs)
     client = make_worker_client(nodegroup_mine)
     response = client.post(
         self.get_tag_uri(tag), {
             'op': 'update_nodes',
             'add': [node_theirs.system_id],
             'nodegroup': nodegroup_mine.uuid,
         })
     self.assertEqual(httplib.OK, response.status_code)
     parsed_result = json.loads(response.content)
     self.assertEqual({'added': 0, 'removed': 0}, parsed_result)
     self.assertItemsEqual([], tag.node_set.all())
Example #47
0
 def test_cluster_no_boot_images_message_displayed_if_no_boot_images(self):
     nodegroup = factory.make_node_group(
         status=NODEGROUP_STATUS.ACCEPTED)
     response = self.client.get(reverse('settings'))
     document = fromstring(response.content)
     nodegroup_row = document.xpath("//tr[@id='%s']" % nodegroup.uuid)[0]
     self.assertIn('no boot images', nodegroup_row.text_content())
Example #48
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())
Example #49
0
 def test_view_tag_num_queries_is_independent_of_num_nodes(self):
     tag = factory.make_tag()
     tag_link = reverse('tag-view', args=[tag.name])
     nodegroup = factory.make_node_group()
     nodes = [
         factory.make_node(nodegroup=nodegroup, mac=True) for i in range(20)
     ]
     for node in nodes[:10]:
         node.tags.add(tag)
     num_queries, response = self.getNumQueries(self.client.get, tag_link)
     self.assertEqual(
         10,
         len([
             link for link in get_content_links(response)
             if link.startswith('/nodes/node')
         ]))
     # Need to get the tag, and the nodes, and the macs of the nodes
     self.assertTrue(num_queries > 3)
     for node in nodes[10:]:
         node.tags.add(tag)
     num_bonus_queries, response = self.getNumQueries(
         self.client.get, tag_link)
     self.assertEqual(num_queries, num_bonus_queries)
     self.assertEqual(
         20,
         len([
             link for link in get_content_links(response)
             if link.startswith('/nodes/node')
         ]))
Example #50
0
    def test_PUT_reserved_to_admin_users(self):
        nodegroup = factory.make_node_group()
        response = self.client_put(
            reverse('nodegroup_handler', args=[nodegroup.uuid]),
            {'name': factory.make_name("new-name")})

        self.assertEqual(httplib.FORBIDDEN, response.status_code)
Example #51
0
 def test_returns_accepted_for_new_pending_nodegroup(self):
     nodegroup = factory.make_node_group(status=NODEGROUP_STATUS.PENDING)
     response = api.compose_nodegroup_register_response(
         nodegroup, already_existed=False)
     self.assertEqual((httplib.ACCEPTED,
                       "Cluster registered.  Awaiting admin approval."),
                      (response.status_code, response.content))
Example #52
0
 def test_update_leases_combines_additions_deletions_and_replacements(self):
     nodegroup = factory.make_node_group()
     mac1 = factory.getRandomMACAddress()
     mac2 = factory.getRandomMACAddress()
     obsolete_lease = factory.make_dhcp_lease(
         nodegroup=nodegroup, mac=mac1)
     # The obsolete lease won't be in the update, so it'll disappear.
     ignore_unused(obsolete_lease)
     unchanged_lease = factory.make_dhcp_lease(
         nodegroup=nodegroup, mac=mac1)
     reassigned_lease = factory.make_dhcp_lease(
         nodegroup=nodegroup, mac=mac1)
     new_ip = factory.getRandomIPAddress()
     DHCPLease.objects.update_leases(nodegroup, {
         reassigned_lease.ip: mac2,
         unchanged_lease.ip: mac1,
         new_ip: mac1,
     })
     self.assertEqual(
         {
             reassigned_lease.ip: mac2,
             unchanged_lease.ip: mac1,
             new_ip: mac1,
         },
         map_leases(nodegroup))
Example #53
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())
Example #54
0
 def test_refreshes_nodegroup_uuid(self):
     refresh_functions = self.patch_refresh_functions()
     nodegroup = factory.make_node_group()
     refresh_worker(nodegroup)
     self.assertEqual(
         [(nodegroup.uuid, )],
         refresh_functions['nodegroup_uuid'].extract_args())
Example #55
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'])
Example #56
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())