コード例 #1
0
 def setUp(self):
     creds = Credentials()
     self.novaservice = NovaClient(creds.get_nova_creds())
     self.fc = FakeInstance()
     self.novaservice._check_keypair = mock.Mock(return_value=True)
     self.novaservice._check_image = Mock(return_value=DEF_IMAGE_ID)
     self.novaservice._check_flavor = Mock(return_value=DEF_FLAVOR_ID)
コード例 #2
0
class TestNovaClient(unittest.TestCase):
    def setUp(self):
        creds = Credentials()
        self.novaservice = NovaClient(creds.get_nova_creds())
        self.fc = FakeInstance()
        self.novaservice._check_keypair = mock.Mock(return_value=True)
        self.novaservice._check_image = Mock(return_value=DEF_IMAGE_ID)
        self.novaservice._check_flavor = Mock(return_value=DEF_FLAVOR_ID)

    def test_create_instance(self):
        self.novaservice.nc.servers.create = Mock(return_value=self.fc)
        expected = '12345'
        self.assertEqual(self.novaservice.create_new_instance(
            DEF_NAME, DEF_IMAGE_ID, DEF_FLAVOR_ID, SSH_MY_KEY), expected)
        self.novaservice._check_keypair.assert_called_with(SSH_MY_KEY)
        self.novaservice._check_image.assert_called_with(DEF_IMAGE_ID)
        self.novaservice._check_flavor.assert_called_with(DEF_FLAVOR_ID)