def validate_keypair(cli, keypair): """Validate keypair""" try: cli.nova().keypairs.get(keypair) except nova_exception.NotFound: raise exception.KeyPairNotFound(keypair=keypair)
def check_keypair_exists(self, context, keypair): """Checks the existence of the keypair""" cli = clients.OpenStackClients(context) try: cli.nova().keypairs.get(keypair) except nova_exc.NotFound: raise exception.KeyPairNotFound(keypair=keypair)
def test_create_bay_with_invalid_keypair(self, mock_valid_os_res): bdict = apiutils.bay_post_data() mock_valid_os_res.side_effect = exception.KeyPairNotFound('test-key') response = self.post_json('/bays', bdict, expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertTrue(mock_valid_os_res.called) self.assertEqual(404, response.status_int)
def test_create_baymodel_with_no_exist_keypair(self, mock_image_data): self.mock_valid_os_res.side_effect = exception.KeyPairNotFound("Test") mock_image_data.return_value = {'name': 'mock_name', 'os_distro': 'fedora-atomic'} bdict = apiutils.baymodel_post_data() response = self.post_json('/baymodels', bdict, expect_errors=True) self.assertEqual(404, response.status_int)
def test_replace_baymodel_with_no_exist_keypair_id(self): self.mock_valid_os_res.side_effect = exception.KeyPairNotFound("aaa") response = self.patch_json('/baymodels/%s' % self.baymodel.uuid, [{'path': '/keypair_id', 'value': 'aaa', 'op': 'replace'}], expect_errors=True) self.assertEqual('application/json', response.content_type) self.assertEqual(404, response.status_code) self.assertTrue(response.json['errors'])
def validate_keypair(cli, keypair): """Validate keypair validate the keypair, if provided. """ if keypair is None: return try: cli.nova().keypairs.get(keypair) except nova_exception.NotFound: raise exception.KeyPairNotFound(keypair=keypair)