Restrict fake db_api calls to db_api interface exactly
Change-Id: I3d32ddb7e49f12d97fc09eec4c203746c9200778
This commit is contained in:
parent
7baa2b3a80
commit
6aa510365c
|
@ -20,6 +20,7 @@ from oslotest import base as test_base
|
|||
|
||||
import ec2api.api.apirequest
|
||||
from ec2api.api import ec2utils
|
||||
import ec2api.db.sqlalchemy.api
|
||||
from ec2api.tests.unit import fakes
|
||||
from ec2api.tests.unit import matchers
|
||||
from ec2api.tests.unit import tools
|
||||
|
@ -65,7 +66,8 @@ class ApiTestCase(test_base.BaseTestCase):
|
|||
self.cinder = cinder_patcher.start().return_value
|
||||
self.addCleanup(cinder_patcher.stop)
|
||||
|
||||
db_api_patcher = mock.patch('ec2api.db.api.IMPL')
|
||||
db_api_patcher = mock.patch('ec2api.db.api.IMPL',
|
||||
autospec=ec2api.db.sqlalchemy.api)
|
||||
self.db_api = db_api_patcher.start()
|
||||
self.addCleanup(db_api_patcher.stop)
|
||||
|
||||
|
|
|
@ -782,7 +782,7 @@ EC2_DHCP_OPTIONS_2 = {
|
|||
|
||||
OS_DHCP_OPTIONS_1 = {'extra_dhcp_opts': [{'opt_name': 'domain-name',
|
||||
'opt_value': 'my.domain.com'},
|
||||
{'opt_name': 'dns-servers',
|
||||
{'opt_name': 'dns-server',
|
||||
'opt_value': '8.8.8.8,127.0.0.1'}]}
|
||||
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
|
||||
from ec2api.tests.unit import base
|
||||
from ec2api.tests.unit import fakes
|
||||
|
@ -20,6 +21,9 @@ from ec2api.tests.unit import matchers
|
|||
from ec2api.tests.unit import tools
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class DhcpOptionsTestCase(base.ApiTestCase):
|
||||
|
||||
def test_create_dhcp_options(self):
|
||||
|
@ -72,10 +76,10 @@ class DhcpOptionsTestCase(base.ApiTestCase):
|
|||
{'dhcpOptionsId': fakes.ID_EC2_DHCP_OPTIONS_1})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_has_call(
|
||||
self.db_api.get_item_by_id.assert_any_call(
|
||||
mock.ANY,
|
||||
fakes.ID_EC2_DHCP_OPTIONS_1)
|
||||
self.db_api.get_items.assert_has_call(
|
||||
self.db_api.get_items.assert_any_call(
|
||||
mock.ANY,
|
||||
'vpc')
|
||||
self.db_api.delete_item.assert_called_once_with(
|
||||
|
@ -137,14 +141,15 @@ class DhcpOptionsTestCase(base.ApiTestCase):
|
|||
'vpcId': fakes.ID_EC2_VPC_1})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.update_item.assert_has_call(
|
||||
self.db_api.update_item.assert_any_call(
|
||||
mock.ANY,
|
||||
tools.update_dict(
|
||||
fakes.DB_VPC_1,
|
||||
{'dhcp_options_id': db_dhcp_options_id}))
|
||||
self.neutron.update_port.assert_has_call(
|
||||
mock.ANY, fakes.ID_OS_PORT_1,
|
||||
{'port': os_dhcp_options})
|
||||
self.assert_any_call(
|
||||
self.neutron.update_port,
|
||||
fakes.ID_OS_PORT_1,
|
||||
{'port': self._effective_os_dhcp_options(os_dhcp_options)})
|
||||
|
||||
check(fakes.ID_EC2_DHCP_OPTIONS_1, fakes.ID_EC2_DHCP_OPTIONS_1,
|
||||
fakes.OS_DHCP_OPTIONS_1)
|
||||
|
@ -180,3 +185,11 @@ class DhcpOptionsTestCase(base.ApiTestCase):
|
|||
{'port': fakes.OS_DHCP_OPTIONS_1})
|
||||
self.db_api.update_item.assert_any_call(
|
||||
mock.ANY, vpc)
|
||||
|
||||
def _effective_os_dhcp_options(self, os_dhcp_options):
|
||||
dhcp_opts = {
|
||||
'extra_dhcp_opts': [{'opt_name': 'mtu',
|
||||
'opt_value': str(CONF.network_device_mtu)}]}
|
||||
dhcp_opts['extra_dhcp_opts'].extend(
|
||||
os_dhcp_options.get('extra_dhcp_opts', []))
|
||||
return dhcp_opts
|
||||
|
|
|
@ -277,7 +277,7 @@ class NetworkInterfaceTestCase(base.ApiTestCase):
|
|||
fakes.ID_EC2_NETWORK_INTERFACE_1})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_has_call(
|
||||
self.db_api.get_item_by_id.assert_any_call(
|
||||
mock.ANY,
|
||||
fakes.ID_EC2_NETWORK_INTERFACE_1)
|
||||
self.db_api.delete_item.assert_called_once_with(
|
||||
|
@ -336,7 +336,7 @@ class NetworkInterfaceTestCase(base.ApiTestCase):
|
|||
fakes.ID_EC2_NETWORK_INTERFACE_1})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_has_call(
|
||||
self.db_api.get_item_by_id.assert_any_call(
|
||||
mock.ANY,
|
||||
fakes.ID_EC2_NETWORK_INTERFACE_1)
|
||||
self.db_api.delete_item.assert_called_once_with(
|
||||
|
@ -521,19 +521,19 @@ class NetworkInterfaceTestCase(base.ApiTestCase):
|
|||
|
||||
def test_attach_network_interface_rollback(self):
|
||||
self.db_api.get_item_by_id.return_value = (
|
||||
copy.deepcopy(fakes.DB_NETWORK_INTERFACE_2))
|
||||
copy.deepcopy(fakes.DB_NETWORK_INTERFACE_1))
|
||||
self.neutron.list_ports.return_value = (
|
||||
{'ports': [fakes.OS_PORT_2]})
|
||||
self.isotime.return_value = fakes.TIME_ATTACH_NETWORK_INTERFACE
|
||||
self.nova_servers.interface_attach.side_effect = Exception()
|
||||
|
||||
self.execute('AttachNetworkInterface',
|
||||
{'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_2,
|
||||
{'NetworkInterfaceId': fakes.ID_EC2_NETWORK_INTERFACE_1,
|
||||
'InstanceId': fakes.ID_EC2_INSTANCE_1,
|
||||
'DeviceIndex': '1'})
|
||||
|
||||
self.db_api.update_item.assert_has_call(
|
||||
mock.ANY, fakes.DB_NETWORK_INTERFACE_2)
|
||||
self.db_api.update_item.assert_any_call(
|
||||
mock.ANY, fakes.DB_NETWORK_INTERFACE_1)
|
||||
|
||||
def test_detach_network_interface(self):
|
||||
network_interface = tools.update_dict(fakes.DB_NETWORK_INTERFACE_2,
|
||||
|
|
|
@ -167,7 +167,7 @@ class SecurityGroupTestCase(base.ApiTestCase):
|
|||
fakes.ID_EC2_SECURITY_GROUP_1})
|
||||
self.assertEqual(200, resp['http_status_code'])
|
||||
self.assertEqual(True, resp['return'])
|
||||
self.db_api.get_item_by_id.assert_has_call(
|
||||
self.db_api.get_item_by_id.assert_any_call(
|
||||
mock.ANY,
|
||||
fakes.ID_EC2_SECURITY_GROUP_1)
|
||||
self.db_api.delete_item.assert_called_once_with(
|
||||
|
|
Loading…
Reference in New Issue