def test_list_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() client = make_worker_client(nodegroup) response = client.get( reverse('nodegroupinterfaces_handler', args=[nodegroup.uuid]), {'op': 'list'}) self.assertEqual(httplib.OK, response.status_code)
def test_POST_update_nodes_allows_rack_controller(self): tag = factory.make_Tag() rack_controller = factory.make_RackController() node = factory.make_Node() client = make_worker_client(rack_controller) tokens = list(get_auth_tokens(rack_controller.owner)) if len(tokens) > 0: # Use the latest token. token = tokens[-1] else: token = create_auth_token(rack_controller.owner) token.save() creds = convert_tuple_to_string(get_creds_tuple(token)) response = client.post( self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], 'rack_controller': rack_controller.system_id, 'credentials': creds, }) self.assertEqual(http.client.OK, response.status_code) parsed_result = json.loads( response.content.decode(settings.DEFAULT_CHARSET)) self.assertEqual({'added': 1, 'removed': 0}, parsed_result) self.assertItemsEqual([node], tag.node_set.all())
def test_details_with_no_details(self): # If there are no nodes, an empty map is returned. nodegroup = factory.make_node_group() client = make_worker_client(nodegroup) response = self.make_details_request(client, nodegroup) self.assertEqual(httplib.OK, response.status_code) parsed_result = bson.BSON(response.content).decode() self.assertDictEqual({}, parsed_result)
def test_report_boot_images_ignores_unknown_image_properties(self): nodegroup = NodeGroup.objects.ensure_master() image = make_boot_image_params() image['nonesuch'] = factory.make_name('nonesuch'), client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual((httplib.OK, "OK"), (response.status_code, response.content))
def test_update_leases_works_for_nodegroup_worker(self): nodegroup = factory.make_node_group() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), {'op': 'update_leases', 'leases': json.dumps({})}) self.assertEqual( httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response))
def test_report_boot_images_stores_images(self): nodegroup = NodeGroup.objects.ensure_master() image = make_boot_image_params() client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual((httplib.OK, "OK"), (response.status_code, response.content)) self.assertTrue( BootImage.objects.have_image(nodegroup=nodegroup, **image))
def test_delete_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() interface = factory.make_node_group_interface( nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP) self.client = make_worker_client(nodegroup) response = self.client.delete( reverse('nodegroupinterface_handler', args=[nodegroup.uuid, interface.interface])) self.assertEqual(httplib.NO_CONTENT, response.status_code)
def test_report_boot_images_ignores_unknown_image_properties(self): nodegroup = NodeGroup.objects.ensure_master() image = make_boot_image_params() image['nonesuch'] = factory.make_name('nonesuch'), client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual( (httplib.OK, "OK"), (response.status_code, response.content))
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)
def test_report_boot_images_stores_images(self): nodegroup = NodeGroup.objects.ensure_master() image = make_boot_image_params() client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual( (httplib.OK, "OK"), (response.status_code, response.content)) self.assertTrue( BootImage.objects.have_image(nodegroup=nodegroup, **image))
def test_update_leases_works_for_nodegroup_worker(self): nodegroup = factory.make_node_group() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'update_leases', 'leases': json.dumps({}) }) self.assertEqual(httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response))
def test_delete_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() interface = factory.make_node_group_interface( nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP) self.client = make_worker_client(nodegroup) response = self.client.delete( reverse( 'nodegroupinterface_handler', args=[nodegroup.uuid, interface.interface])) self.assertEqual(httplib.NO_CONTENT, response.status_code)
def test_POST_update_nodes_refuses_unidentified_nodegroup_worker(self): tag = factory.make_tag() nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) # We don't pass nodegroup:uuid so we get refused response = client.post(self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], }) self.assertEqual(httplib.FORBIDDEN, response.status_code) self.assertItemsEqual([], tag.node_set.all())
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))
def test_POST_update_nodes_refuses_unidentified_rack_controller(self): tag = factory.make_Tag() rack_controller = factory.make_RackController() node = factory.make_Node() client = make_worker_client(rack_controller) # We don't pass rack controller system_id so we get refused. response = client.post( self.get_tag_uri(tag), {"op": "update_nodes", "add": [node.system_id]}, ) self.assertEqual(http.client.FORBIDDEN, response.status_code) self.assertItemsEqual([], tag.node_set.all())
def test_nodegroup_list_nodes_works_for_nodegroup_worker(self): nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) response = client.get( reverse('nodegroup_handler', args=[nodegroup.uuid]), {'op': 'list_nodes'}) self.assertEqual(httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) parsed_result = json.loads(response.content) self.assertItemsEqual([node.system_id], parsed_result)
def test_POST_update_nodes_refuses_unidentified_nodegroup_worker(self): tag = factory.make_tag() nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) # We don't pass nodegroup:uuid so we get refused response = client.post( self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], }) self.assertEqual(httplib.FORBIDDEN, response.status_code) self.assertItemsEqual([], tag.node_set.all())
def test_update_leases_processes_empty_leases_dict(self): nodegroup = factory.make_node_group() factory.make_dhcp_lease(nodegroup=nodegroup) client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'update_leases', 'leases': json.dumps({}), }) self.assertEqual((httplib.OK, "Leases updated."), (response.status_code, response.content)) self.assertItemsEqual([], DHCPLease.objects.filter(nodegroup=nodegroup))
def test_POST_report_download_progress_works_for_nodegroup_worker(self): nodegroup = factory.make_node_group() filename = factory.getRandomString() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': filename, }) self.assertEqual(httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response))
def test_report_download_progress_rejects_invalid_data(self): progress = factory.make_download_progress_incomplete() client = make_worker_client(progress.nodegroup) response = client.post( reverse('nodegroup_handler', args=[progress.nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': progress.filename, 'bytes_downloaded': -1, }) self.assertEqual( httplib.BAD_REQUEST, response.status_code, explain_unexpected_response(httplib.BAD_REQUEST, response))
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)
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_new_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroupinterfaces_handler', args=[nodegroup.uuid]), {'op': 'new'}) # It's a bad request because we've not entered all the required # data but it's not FORBIDDEN which means we passed the test. self.assertEqual(( httplib.BAD_REQUEST, { 'ip': ["This field is required."] }, ), (response.status_code, json.loads(response.content)))
def test_new_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroupinterfaces_handler', args=[nodegroup.uuid]), {'op': 'new'}) # It's a bad request because we've not entered all the required # data but it's not FORBIDDEN which means we passed the test. self.assertEqual( ( httplib.BAD_REQUEST, {'ip': ["This field is required."]}, ), (response.status_code, json.loads(response.content)))
def test_update_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() interface = factory.make_node_group_interface( nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP) self.client = make_worker_client(nodegroup) get_ip_in_network = partial(factory.getRandomIPInNetwork, interface.network) new_ip_range_high = next(ip for ip in iter(get_ip_in_network, None) if ip != interface.ip_range_high) response = self.client_put( reverse('nodegroupinterface_handler', args=[nodegroup.uuid, interface.interface]), {'ip_range_high': new_ip_range_high}) self.assertEqual(httplib.OK, response.status_code)
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())
def test_report_boot_images_removes_warning_if_images_found(self): self.patch(api, 'register_persistent_error') self.patch(api, 'discard_persistent_error') nodegroup = factory.make_node_group() image = make_boot_image_params() client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual((httplib.OK, "OK"), (response.status_code, response.content)) self.assertItemsEqual([], api.register_persistent_error.call_args_list) api.discard_persistent_error.assert_called_once_with( COMPONENT.IMPORT_PXE_FILES)
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))
def test_nodegroup_list_nodes_works_for_nodegroup_worker(self): nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) response = client.get( reverse('nodegroup_handler', args=[nodegroup.uuid]), {'op': 'list_nodes'}) self.assertEqual( httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) parsed_result = json.loads(response.content) self.assertItemsEqual([node.system_id], parsed_result)
def test_POST_update_nodes_allows_nodegroup_worker(self): tag = factory.make_tag() nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) response = client.post( self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], 'nodegroup': nodegroup.uuid, }) self.assertEqual(httplib.OK, response.status_code) parsed_result = json.loads(response.content) self.assertEqual({'added': 1, 'removed': 0}, parsed_result) self.assertItemsEqual([node], tag.node_set.all())
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_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))
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)
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])
def test_update_leases_processes_empty_leases_dict(self): nodegroup = factory.make_node_group() factory.make_dhcp_lease(nodegroup=nodegroup) client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'update_leases', 'leases': json.dumps({}), }) self.assertEqual( (httplib.OK, "Leases updated."), (response.status_code, response.content)) self.assertItemsEqual( [], DHCPLease.objects.filter(nodegroup=nodegroup))
def test_report_download_progress_updates_ongoing_download(self): progress = factory.make_download_progress_incomplete() client = make_worker_client(progress.nodegroup) new_bytes_downloaded = progress.bytes_downloaded + 1 response = client.post( reverse('nodegroup_handler', args=[progress.nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': progress.filename, 'bytes_downloaded': new_bytes_downloaded, }) self.assertEqual(httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) progress = reload_object(progress) self.assertEqual(new_bytes_downloaded, progress.bytes_downloaded)
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())
def test_update_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() interface = factory.make_node_group_interface( nodegroup, management=NODEGROUPINTERFACE_MANAGEMENT.DHCP) self.client = make_worker_client(nodegroup) get_ip_in_network = partial( factory.getRandomIPInNetwork, interface.network) new_ip_range_high = next( ip for ip in iter(get_ip_in_network, None) if ip != interface.ip_range_high) response = self.client_put( reverse( 'nodegroupinterface_handler', args=[nodegroup.uuid, interface.interface]), {'ip_range_high': new_ip_range_high}) self.assertEqual(httplib.OK, response.status_code)
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) ])
def test_report_boot_images_removes_warning_if_images_found(self): self.patch(api, 'register_persistent_error') self.patch(api, 'discard_persistent_error') nodegroup = factory.make_node_group() image = make_boot_image_params() client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [image], client=client) self.assertEqual( (httplib.OK, "OK"), (response.status_code, response.content)) self.assertItemsEqual( [], api.register_persistent_error.call_args_list) api.discard_persistent_error.assert_called_once_with( COMPONENT.IMPORT_PXE_FILES)
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])
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())
def test_report_download_progress_updates_ongoing_download(self): progress = factory.make_download_progress_incomplete() client = make_worker_client(progress.nodegroup) new_bytes_downloaded = progress.bytes_downloaded + 1 response = client.post( reverse('nodegroup_handler', args=[progress.nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': progress.filename, 'bytes_downloaded': new_bytes_downloaded, }) self.assertEqual( httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) progress = reload_object(progress) self.assertEqual(new_bytes_downloaded, progress.bytes_downloaded)
def test_POST_update_nodes_ignores_incorrect_definition(self): tag = factory.make_tag() orig_def = tag.definition nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) client = make_worker_client(nodegroup) tag.definition = '//new/node/definition' tag.save() response = client.post( self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], 'nodegroup': nodegroup.uuid, 'definition': orig_def, }) self.assertEqual(httplib.CONFLICT, response.status_code) self.assertItemsEqual([], tag.node_set.all()) self.assertItemsEqual([], node.tags.all())
def test_POST_update_nodes_ignores_incorrect_definition(self): tag = factory.make_Tag() orig_def = tag.definition rack_controller = factory.make_RackController() node = factory.make_Node() client = make_worker_client(rack_controller) tag.definition = '//new/node/definition' tag.save(populate=False) response = client.post( self.get_tag_uri(tag), { 'op': 'update_nodes', 'add': [node.system_id], 'rack_controller': rack_controller.system_id, 'definition': orig_def, }) self.assertEqual(http.client.CONFLICT, response.status_code) self.assertItemsEqual([], tag.node_set.all()) self.assertItemsEqual([], node.tags.all())
def test_report_download_progress_accepts_new_download(self): nodegroup = factory.make_node_group() filename = factory.getRandomString() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': filename, }) self.assertEqual(httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) progress = DownloadProgress.objects.get(nodegroup=nodegroup) self.assertEqual(nodegroup, progress.nodegroup) self.assertEqual(filename, progress.filename) self.assertIsNone(progress.size) self.assertIsNone(progress.bytes_downloaded) self.assertEqual('', progress.error)
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) ])
def test_report_download_progress_accepts_new_download(self): nodegroup = factory.make_node_group() filename = factory.getRandomString() client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'report_download_progress', 'filename': filename, }) self.assertEqual( httplib.OK, response.status_code, explain_unexpected_response(httplib.OK, response)) progress = DownloadProgress.objects.get(nodegroup=nodegroup) self.assertEqual(nodegroup, progress.nodegroup) self.assertEqual(filename, progress.filename) self.assertIsNone(progress.size) self.assertIsNone(progress.bytes_downloaded) self.assertEqual('', progress.error)
def test_details_returns_details(self): nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) self.set_lshw_details(node, self.example_lshw_details) self.set_lldp_details(node, self.example_lldp_details) client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), {'op': 'details', 'system_ids': [node.system_id]}) self.assertEqual(httplib.OK, response.status_code) parsed_result = bson.BSON(response.content).decode() self.assertDictEqual( { node.system_id: { "lshw": self.example_lshw_details_bin, "lldp": self.example_lldp_details_bin, }, }, parsed_result)
def test_empty_details(self): # Empty details are passed through. nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) self.set_lshw_details(node, b'') self.set_lldp_details(node, b'') client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), {'op': 'details', 'system_ids': [node.system_id]}) self.assertEqual(httplib.OK, response.status_code) parsed_result = bson.BSON(response.content).decode() self.assertDictEqual( { node.system_id: { "lshw": bson.binary.Binary(b""), "lldp": bson.binary.Binary(b""), }, }, parsed_result)
def test_details_returns_details(self): nodegroup = factory.make_node_group() node = factory.make_node(nodegroup=nodegroup) self.set_lshw_details(node, self.example_lshw_details) self.set_lldp_details(node, self.example_lldp_details) client = make_worker_client(nodegroup) response = client.post( reverse('nodegroup_handler', args=[nodegroup.uuid]), { 'op': 'details', 'system_ids': [node.system_id] }) self.assertEqual(httplib.OK, response.status_code) parsed_result = bson.BSON(response.content).decode() self.assertDictEqual( { node.system_id: { "lshw": self.example_lshw_details_bin, "lldp": self.example_lldp_details_bin, }, }, parsed_result)
def test_report_boot_images_works_for_master_worker(self): nodegroup = NodeGroup.objects.ensure_master() client = make_worker_client(nodegroup) response = self.report_images(nodegroup, [], client=client) self.assertEqual(httplib.OK, response.status_code)