def setUp(self): self.public_key = fake_crypto.get_ssh_public_key() self.fingerprint = '1e:2c:9b:56:79:4b:45:77:f9:ca:7a:98:2c:b0:d5:3c' def fake_get_nw_info(cls, ctxt, instance): self.assertTrue(ctxt.is_admin) return fake_network.fake_get_instance_nw_info(self, 1, 1) super(UsageInfoTestCase, self).setUp() self.stub_out('nova.network.api.get_instance_nw_info', fake_get_nw_info) fake_notifier.stub_notifier(self) self.addCleanup(fake_notifier.reset) self.flags(compute_driver='fake.FakeDriver', network_manager='nova.network.manager.FlatManager') self.compute = manager.ComputeManager() self.user_id = 'fake' self.project_id = 'fake' self.context = context.RequestContext(self.user_id, self.project_id) def fake_show(meh, context, id, **kwargs): return {'id': 1, 'properties': {'kernel_id': 1, 'ramdisk_id': 1}} self.flags(group='glance', api_servers=['http://localhost:9292']) self.stub_out('nova.tests.unit.image.fake._FakeImageService.show', fake_show) fake_network.set_stub_network_methods(self) fake_server_actions.stub_out_action_events(self)
def test_keypairs_import_key_post(self): # NOTE(claudiub): overrides the method with the same name in # KeypairsSampleJsonTest, since the API sample expects a keypair_type. public_key = fake_crypto.get_ssh_public_key() self._check_keypairs_import_key_post( public_key, keypair_type=keypair_obj.KEYPAIR_TYPE_SSH, user_id="fake")
def test_keypair_create_for_user(self): subs = { "keypair_type": keypair_obj.KEYPAIR_TYPE_SSH, "public_key": fake_crypto.get_ssh_public_key(), "user_id": "fake", } self._check_keypairs_post(**subs)
def test_keypair_create_for_user(self): subs = { 'keypair_type': keypair_obj.KEYPAIR_TYPE_SSH, 'public_key': fake_crypto.get_ssh_public_key(), 'user_id': "fake" } self._check_keypairs_post(**subs)
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None): # We have to depend on a specific image and flavor to fix the content # of the notification that will be emitted flavor_body = { 'flavor': { 'name': 'test_flavor', 'ram': 512, 'vcpus': 1, 'disk': 1, 'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e3' } } flavor_id = self.api.post_flavor(flavor_body)['id'] extra_specs = {"extra_specs": {"hw:watchdog_action": "disabled"}} self.admin_api.post_extra_spec(flavor_id, extra_specs) # Ignore the create flavor notification fake_notifier.reset() keypair_req = { "keypair": { "name": "my-key", "public_key": fake_crypto.get_ssh_public_key() } } self.api.post_keypair(keypair_req) server = self._build_minimal_create_server_request( self.api, 'some-server', image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6', flavor_id=flavor_id) # NOTE(gibi): from microversion 2.19 the description is not set to the # instance name automatically but can be provided at boot. server['description'] = 'some-server' if extra_params: extra_params['return_reservation_id'] = True extra_params['key_name'] = 'my-key' server.update(extra_params) post = {'server': server} created_server = self.api.post_server(post) reservation_id = created_server['reservation_id'] created_server = self.api.get_servers( detail=False, search_opts={'reservation_id': reservation_id})[0] self.assertTrue(created_server['id']) # Wait for it to finish being created found_server = self._wait_for_state_change(self.api, created_server, expected_status) found_server['reservation_id'] = reservation_id if found_server['status'] == 'ACTIVE': self.api.put_server_tags(found_server['id'], ['tag1']) return found_server
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None): # We have to depend on a specific image and flavor to fix the content # of the notification that will be emitted flavor_body = {'flavor': {'name': 'test_flavor', 'ram': 512, 'vcpus': 1, 'disk': 1, 'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e3' }} flavor_id = self.api.post_flavor(flavor_body)['id'] extra_specs = { "extra_specs": { "hw:watchdog_action": "disabled"}} self.admin_api.post_extra_spec(flavor_id, extra_specs) # Ignore the create flavor notification fake_notifier.reset() keypair_req = { "keypair": { "name": "my-key", "public_key": fake_crypto.get_ssh_public_key() }} self.api.post_keypair(keypair_req) server = self._build_minimal_create_server_request( self.api, 'some-server', image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6', flavor_id=flavor_id) # NOTE(gibi): from microversion 2.19 the description is not set to the # instance name automatically but can be provided at boot. server['description'] = 'some-server' if extra_params: extra_params['return_reservation_id'] = True extra_params['key_name'] = 'my-key' server.update(extra_params) post = {'server': server} created_server = self.api.post_server(post) reservation_id = created_server['reservation_id'] created_server = self.api.get_servers( detail=False, search_opts={'reservation_id': reservation_id})[0] self.assertTrue(created_server['id']) # Wait for it to finish being created found_server = self._wait_for_state_change(self.api, created_server, expected_status) found_server['reservation_id'] = reservation_id if found_server['status'] == 'ACTIVE': self.api.put_server_tags(found_server['id'], ['tag1']) return found_server
def test_keypairs_delete_for_user(self): # Delete a keypair on behalf of a user subs = { "keypair_type": keypair_obj.KEYPAIR_TYPE_SSH, "public_key": fake_crypto.get_ssh_public_key(), "user_id": "fake", } key_name = self._check_keypairs_post(**subs) response = self._do_delete("os-keypairs/%s?user_id=fake" % key_name, api_version=self.request_api_version) self.assertEqual(self.expected_delete_status_code, response.status_code)
def _check_keypairs_import_key_post_invalid(self, keypair_type): key_name = 'keypair-' + str(uuid.uuid4()) subs = { 'keypair_name': key_name, 'keypair_type': keypair_type, 'public_key': fake_crypto.get_ssh_public_key() } response = self._do_post('os-keypairs', 'keypairs-import-post-req', subs) self.assertEqual(400, response.status_code)
def test_keypairs_delete_for_user(self): # Delete a keypair on behalf of a user subs = { 'keypair_type': keypair_obj.KEYPAIR_TYPE_SSH, 'public_key': fake_crypto.get_ssh_public_key(), 'user_id': "fake" } key_name = self._check_keypairs_post(**subs) response = self._do_delete('os-keypairs/%s?user_id=fake' % key_name) self.assertEqual(self.expected_delete_status_code, response.status_code)
def _check_keypairs_import_key_post_invalid(self, keypair_type): key_name = 'keypair-' + str(uuid.uuid4()) subs = { 'keypair_name': key_name, 'keypair_type': keypair_type, 'public_key': fake_crypto.get_ssh_public_key() } response = self._do_post('os-keypairs', 'keypairs-import-post-req', subs, api_version=self.request_api_version) self.assertEqual(400, response.status_code)
def _check_keypairs_import_key_post_invalid(self, keypair_type): key_name = 'keypair-' + uuids.fake subs = { 'keypair_name': key_name, 'keypair_type': keypair_type, 'public_key': fake_crypto.get_ssh_public_key() } response = self._do_post('os-keypairs', 'keypairs-import-post-req', subs) self.assertEqual(400, response.status_code)
def _check_keypairs_import_key_post_invalid(self, keypair_type): key_name = "keypair-" + str(uuid.uuid4()) subs = {"keypair_name": key_name, "keypair_type": keypair_type, "public_key": fake_crypto.get_ssh_public_key()} response = self._do_post("os-keypairs", "keypairs-import-post-req", subs, api_version=self.request_api_version) self.assertEqual(400, response.status_code)
def test_keypairs_import_key_post(self): public_key = fake_crypto.get_ssh_public_key() self._check_keypairs_import_key_post(public_key)
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None, scheduler_hints=None, additional_extra_specs=None): # We have to depend on a specific image and flavor to fix the content # of the notification that will be emitted flavor_body = { 'flavor': { 'name': 'test_flavor', 'ram': 512, 'vcpus': 1, 'disk': 1, 'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e3' } } flavor_id = self.api.post_flavor(flavor_body)['id'] extra_specs = {"extra_specs": {"hw:watchdog_action": "disabled"}} if additional_extra_specs: extra_specs['extra_specs'].update(additional_extra_specs) self.admin_api.post_extra_spec(flavor_id, extra_specs) # Ignore the create flavor notification fake_notifier.reset() keypair_req = { "keypair": { "name": "my-key", "public_key": fake_crypto.get_ssh_public_key() } } self.api.post_keypair(keypair_req) keypair_expected_notifications = [ 'keypair-import-start', 'keypair-import-end' ] self.assertLessEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) for notification in keypair_expected_notifications: self._verify_notification( notification, actual=fake_notifier.VERSIONED_NOTIFICATIONS.pop(0)) server = self._build_server( name='some-server', image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6', flavor_id=flavor_id) # NOTE(gibi): from microversion 2.19 the description is not set to the # instance name automatically but can be provided at boot. server['description'] = 'some-server' if extra_params: extra_params['return_reservation_id'] = True extra_params['key_name'] = 'my-key' server.update(extra_params) post = {'server': server} if scheduler_hints: post.update({"os:scheduler_hints": scheduler_hints}) created_server = self.api.post_server(post) reservation_id = created_server['reservation_id'] created_server = self.api.get_servers( detail=False, search_opts={'reservation_id': reservation_id})[0] self.assertTrue(created_server['id']) # Wait for it to finish being created found_server = self._wait_for_state_change(created_server, expected_status) found_server['reservation_id'] = reservation_id # Note(elod.illes): let's just pop and verify the dest_select # notifications if we don't have a special case if scheduler_hints is None and expected_status != 'ERROR': self._pop_and_verify_dest_select_notification(found_server['id']) if found_server['status'] == 'ACTIVE': self.api.put_server_tags(found_server['id'], ['tag1']) return found_server
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None, scheduler_hints=None, additional_extra_specs=None): # We have to depend on a specific image and flavor to fix the content # of the notification that will be emitted flavor_body = {'flavor': {'name': 'test_flavor', 'ram': 512, 'vcpus': 1, 'disk': 1, 'id': 'a22d5517-147c-4147-a0d1-e698df5cd4e3' }} flavor_id = self.api.post_flavor(flavor_body)['id'] extra_specs = { "extra_specs": { "hw:watchdog_action": "disabled"}} if additional_extra_specs: extra_specs['extra_specs'].update(additional_extra_specs) self.admin_api.post_extra_spec(flavor_id, extra_specs) # Ignore the create flavor notification fake_notifier.reset() keypair_req = { "keypair": { "name": "my-key", "public_key": fake_crypto.get_ssh_public_key() }} self.api.post_keypair(keypair_req) keypair_expected_notifications = [ 'keypair-import-start', 'keypair-import-end' ] self.assertLessEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS)) for notification in keypair_expected_notifications: self._verify_notification( notification, actual=fake_notifier.VERSIONED_NOTIFICATIONS.pop(0)) server = self._build_minimal_create_server_request( self.api, 'some-server', image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6', flavor_id=flavor_id) # NOTE(gibi): from microversion 2.19 the description is not set to the # instance name automatically but can be provided at boot. server['description'] = 'some-server' if extra_params: extra_params['return_reservation_id'] = True extra_params['key_name'] = 'my-key' server.update(extra_params) post = {'server': server} if scheduler_hints: post.update({"os:scheduler_hints": scheduler_hints}) created_server = self.api.post_server(post) reservation_id = created_server['reservation_id'] created_server = self.api.get_servers( detail=False, search_opts={'reservation_id': reservation_id})[0] self.assertTrue(created_server['id']) # Wait for it to finish being created found_server = self._wait_for_state_change(self.api, created_server, expected_status) found_server['reservation_id'] = reservation_id # Note(elod.illes): let's just pop and verify the dest_select # notifications if we don't have a special case if scheduler_hints is None and expected_status != 'ERROR': self._pop_and_verify_dest_select_notification(found_server['id']) if found_server['status'] == 'ACTIVE': self.api.put_server_tags(found_server['id'], ['tag1']) return found_server