Exemplo n.º 1
0
def validate_keypair(cli, keypair):
    """Validate keypair"""

    try:
        cli.nova().keypairs.get(keypair)
    except nova_exception.NotFound:
        raise exception.KeyPairNotFound(keypair=keypair)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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)
Exemplo n.º 5
0
 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'])
Exemplo n.º 6
0
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)