Esempio n. 1
0
    def test_create_network_raises_VMWareDVSException(self):
        # first we count calls
        self.controller.create_network(fake_network, fake_segment)
        api_calls = self.connection.invoke_api.call_count

        # then we throw VimException for every api call
        for i in range(api_calls):
            connection = self._get_connection_mock(self.dvs_name)
            org_side_effect = self.connection.invoke_api.side_effect

            def side_effect(*args, **kwargs):
                if connection.invoke_api.call_count == i + 1:
                    msg = ('Failed test with args: %(args)s '
                           'and kwargs: %(kwargs)s' % {
                               'args': args,
                               'kwargs': kwargs
                           })
                    raise vmware_exceptions.VimException(msg)
                return org_side_effect(*args, **kwargs)

            connection.invoke_api.side_effect = side_effect
            controller = dvs_util.DVSController(self.dvs_name,
                                                self.cluster_name, connection)
            self.assertRaises(exceptions.VMWareDVSException,
                              controller.create_network, fake_network,
                              fake_segment)
Esempio n. 2
0
    def setUp(self):
        super(DVSControllerBaseTestCase, self).setUp()
        self.dvs_name = 'dvs_name'
        self.vim = mock.Mock()
        self.connection = self._get_connection_mock(self.dvs_name)

        self.cluster_name = 'Cluster1'
        self.dvs = mock.Mock()
        self._dvs_uuid = '_dvs_uuid'
        self.cluster = mock.Mock()
        dvs_param = [self.dvs, self._dvs_uuid, self.cluster]
        self.use_patch('networking_vsphere.utils.dvs_util.DVSController.'
                       '_get_dvs', return_value=dvs_param)

        self.controller = dvs_util.DVSController(self.dvs_name,
                                                 self.cluster_name,
                                                 self.connection)
    def setUp(self):
        super(DVSControllerBaseTestCase, self).setUp()
        self.dvs_name = 'dvs_name'
        self.vim = mock.Mock()
        self.connection = self._get_connection_mock(self.dvs_name)

        self.datacenter = 'datacenter1'
        # self.use_patch('vmware_dvs.util.DVSController._get_datacenter',
        #                return_value=self.datacenter)
        self.dvs = mock.Mock()
        dvs_param = [self.dvs, self.datacenter]
        self.use_patch('networking_vsphere.utils.dvs_util.DVSController.'
                       '_get_dvs', return_value=dvs_param)
        self.dvs = dvs_param[0]
        self.datacenter = dvs_param[1]

        self.controller = dvs_util.DVSController(self.dvs_name,
                                                 self.connection)