salt/tests/unit/modules/test_nova.py

298 lines
10 KiB
Python
Raw Normal View History

2015-04-03 09:10:46 +00:00
# -*- coding: utf-8 -*-
'''
:codeauthor: :email:`Rahul Handay <rahulha@saltstack.com>`
'''
2015-04-17 18:00:01 +00:00
# Import Python Libs
from __future__ import absolute_import, unicode_literals, print_function
2015-04-17 18:00:01 +00:00
2015-04-03 09:10:46 +00:00
# Import Salt Testing Libs
2017-03-21 17:57:27 +00:00
from tests.support.mixins import LoaderModuleMockMixin
from tests.support.unit import TestCase, skipIf
from tests.support.mock import (
2015-04-03 09:10:46 +00:00
MagicMock,
patch,
NO_MOCK,
NO_MOCK_REASON
)
# Import Salt Libs
import salt.modules.nova as nova
2015-04-03 09:10:46 +00:00
@skipIf(NO_MOCK, NO_MOCK_REASON)
2017-03-21 17:57:27 +00:00
class NovaTestCase(TestCase, LoaderModuleMockMixin):
2015-04-03 09:10:46 +00:00
'''
Test cases for salt.modules.nova
'''
def setup_loader_modules(self):
2017-04-10 13:00:57 +00:00
patcher = patch('salt.modules.nova._auth')
self.mock_auth = patcher.start()
self.addCleanup(patcher.stop)
self.addCleanup(delattr, self, 'mock_auth')
return {nova: {}}
2017-03-21 17:57:27 +00:00
2017-04-10 13:00:57 +00:00
def test_boot(self):
2015-04-03 09:10:46 +00:00
'''
Test for Boot (create) a new instance
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'boot', MagicMock(return_value='A')):
self.assertTrue(nova.boot('name'))
2017-04-10 13:00:57 +00:00
def test_volume_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for List storage volumes
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_list', MagicMock(return_value='A')):
self.assertTrue(nova.volume_list())
2017-04-10 13:00:57 +00:00
def test_volume_show(self):
2015-04-03 09:10:46 +00:00
'''
Test for Create a block storage volume
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_show', MagicMock(return_value='A')):
self.assertTrue(nova.volume_show('name'))
2017-04-10 13:00:57 +00:00
def test_volume_create(self):
2015-04-03 09:10:46 +00:00
'''
Test for Create a block storage volume
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_create', MagicMock(return_value='A')):
self.assertTrue(nova.volume_create('name'))
2017-04-10 13:00:57 +00:00
def test_volume_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Destroy the volume
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_delete', MagicMock(return_value='A')):
self.assertTrue(nova.volume_delete('name'))
2017-04-10 13:00:57 +00:00
def test_volume_detach(self):
2015-04-03 09:10:46 +00:00
'''
Test for Attach a block storage volume
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_detach', MagicMock(return_value='A')):
self.assertTrue(nova.volume_detach('name'))
2017-04-10 13:00:57 +00:00
def test_volume_attach(self):
2015-04-03 09:10:46 +00:00
'''
Test for Attach a block storage volume
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'volume_attach', MagicMock(return_value='A')):
self.assertTrue(nova.volume_attach('name', 'serv_name'))
2017-04-10 13:00:57 +00:00
def test_suspend(self):
2015-04-03 09:10:46 +00:00
'''
Test for Suspend an instance
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'suspend', MagicMock(return_value='A')):
self.assertTrue(nova.suspend('instance_id'))
2017-04-10 13:00:57 +00:00
def test_resume(self):
2015-04-03 09:10:46 +00:00
'''
Test for Resume an instance
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'resume', MagicMock(return_value='A')):
self.assertTrue(nova.resume('instance_id'))
2017-04-10 13:00:57 +00:00
def test_lock(self):
2015-04-03 09:10:46 +00:00
'''
Test for Lock an instance
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'lock', MagicMock(return_value='A')):
self.assertTrue(nova.lock('instance_id'))
2017-04-10 13:00:57 +00:00
def test_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Delete an instance
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'delete', MagicMock(return_value='A')):
self.assertTrue(nova.delete('instance_id'))
2017-04-10 13:00:57 +00:00
def test_flavor_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return a list of available flavors (nova flavor-list)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'flavor_list', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_list())
2017-04-10 13:00:57 +00:00
def test_flavor_create(self):
2015-04-03 09:10:46 +00:00
'''
Test for Add a flavor to nova (nova flavor-create)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'flavor_create', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_create('name'))
2017-04-10 13:00:57 +00:00
def test_flavor_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Delete a flavor from nova by id (nova flavor-delete)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'flavor_delete', MagicMock(return_value='A')):
self.assertTrue(nova.flavor_delete('flavor_id'))
2017-04-10 13:00:57 +00:00
def test_keypair_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return a list of available keypairs (nova keypair-list)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'keypair_list', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_list())
2017-04-10 13:00:57 +00:00
def test_keypair_add(self):
2015-04-03 09:10:46 +00:00
'''
Test for Add a keypair to nova (nova keypair-add)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'keypair_add', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_add('name'))
2017-04-10 13:00:57 +00:00
def test_keypair_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Add a keypair to nova (nova keypair-delete)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'keypair_delete', MagicMock(return_value='A')):
self.assertTrue(nova.keypair_delete('name'))
2017-04-10 13:00:57 +00:00
def test_image_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return a list of available images
(nova images-list + nova image-show)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'image_list', MagicMock(return_value='A')):
self.assertTrue(nova.image_list())
2017-04-10 13:00:57 +00:00
def test_image_meta_set(self):
2015-04-03 09:10:46 +00:00
'''
Test for Sets a key=value pair in the
metadata for an image (nova image-meta set)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'image_meta_set', MagicMock(return_value='A')):
self.assertTrue(nova.image_meta_set())
2017-04-10 13:00:57 +00:00
def test_image_meta_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Delete a key=value pair from the metadata for an image
(nova image-meta set)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'image_meta_delete', MagicMock(return_value='A')):
self.assertTrue(nova.image_meta_delete())
def test_list_(self):
'''
Test for To maintain the feel of the nova command line,
this function simply calls
the server_list function.
'''
with patch.object(nova, 'server_list', return_value=['A']):
self.assertEqual(nova.list_(), ['A'])
2017-04-10 13:00:57 +00:00
def test_server_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return list of active servers
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'server_list', MagicMock(return_value='A')):
self.assertTrue(nova.server_list())
def test_show(self):
'''
Test for To maintain the feel of the nova command line,
this function simply calls
the server_show function.
'''
with patch.object(nova, 'server_show', return_value=['A']):
self.assertEqual(nova.show('server_id'), ['A'])
2017-04-10 13:00:57 +00:00
def test_server_list_detailed(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return detailed list of active servers
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'server_list_detailed', MagicMock(return_value='A')):
self.assertTrue(nova.server_list_detailed())
2017-04-10 13:00:57 +00:00
def test_server_show(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return detailed information for an active server
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'server_show', MagicMock(return_value='A')):
self.assertTrue(nova.server_show('serv_id'))
2017-04-10 13:00:57 +00:00
def test_secgroup_create(self):
2015-04-03 09:10:46 +00:00
'''
Test for Add a secgroup to nova (nova secgroup-create)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'server_list_detailed', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_create('name', 'desc'))
2017-04-10 13:00:57 +00:00
def test_secgroup_delete(self):
2015-04-03 09:10:46 +00:00
'''
Test for Delete a secgroup to nova (nova secgroup-delete)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'secgroup_delete', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_delete('name'))
2017-04-10 13:00:57 +00:00
def test_secgroup_list(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return a list of available security groups (nova items-list)
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'secgroup_list', MagicMock(return_value='A')):
self.assertTrue(nova.secgroup_list())
2017-04-10 13:00:57 +00:00
def test_server_by_name(self):
2015-04-03 09:10:46 +00:00
'''
Test for Return information about a server
'''
2017-04-10 13:00:57 +00:00
self.mock_auth.side_effect = MagicMock()
with patch.object(self.mock_auth,
2015-04-03 09:10:46 +00:00
'server_by_name', MagicMock(return_value='A')):
self.assertTrue(nova.server_by_name('name'))