コード例 #1
0
 def test_create_vip_without_connection(self):
     with nested(
             self.subnet(),
             mock.patch.object(self.driver.plugin._core_plugin,
                               'get_subnet')) as (subnet, mock_get_subnet):
         mock_get_subnet.return_value = subnet['subnet']
         with self.pool(provider=LBAAS_PROVIDER_NAME) as pool:
             testvip = self._build_testvip_contents(subnet['subnet'],
                                                    pool['pool'])
             expectedvip = self._build_expectedvip_contents(
                 testvip, subnet['subnet'])
             errorcode = ncc_client.NCCException.CONNECTION_ERROR
             self.create_resource_mock.side_effect = (
                 ncc_client.NCCException(errorcode))
             # mock the plugin's update_status()
             self._mock_update_status()
             # reset the create_resource() mock
             self.create_resource_mock.reset_mock()
             # execute the method under test.
             self.driver.create_vip(self.context, testvip)
             # First, assert that update_resource was called once
             # with expected params.
             self.create_resource_mock.assert_called_once_with(
                 None, netscaler_driver.VIPS_RESOURCE,
                 netscaler_driver.VIP_RESOURCE, expectedvip)
             #Finally, assert that the vip object is in ERROR state
             self.mock_update_status_obj.assert_called_once_with(
                 mock.ANY, loadbalancer_db.Vip, testvip['id'],
                 constants.ERROR)
コード例 #2
0
 def test_create_pool_with_error(self):
     with nested(
             self.subnet(),
             mock.patch.object(self.driver.plugin._core_plugin,
                               'get_subnet'),
             mock.patch.object(self.driver.plugin._core_plugin,
                               'get_ports'),
             mock.patch.object(self.driver.plugin._core_plugin,
                               'create_port')) as (subnet, mock_get_subnet,
                                                   mock_get_ports,
                                                   mock_create_port):
         mock_get_subnet.return_value = subnet['subnet']
         mock_get_ports.return_value = None
         mock_create_port.return_value = TESTPOOL_SNAT_PORT
         errorcode = ncc_client.NCCException.CONNECTION_ERROR
         self.create_resource_mock.side_effect = (
             ncc_client.NCCException(errorcode))
         testpool = self._build_testpool_contents(subnet['subnet'])
         expectedpool = self._build_expectedpool_contents(
             testpool, subnet['subnet'])
         # mock the plugin's update_status()
         self._mock_update_status()
         #reset the create_resource() mock
         self.create_resource_mock.reset_mock()
         # execute the method under test.
         self.driver.create_pool(self.context, testpool)
         # Also assert that create_resource was called once
         # with expected params.
         (self.create_resource_mock.assert_called_once_with(
             None, netscaler_driver.POOLS_RESOURCE,
             netscaler_driver.POOL_RESOURCE, expectedpool))
         #Finally, assert that the pool object is in ERROR state
         self.mock_update_status_obj.assert_called_once_with(
             mock.ANY, loadbalancer_db.Pool, expectedpool['id'],
             constants.ERROR)
コード例 #3
0
 def _set_response_error(self, mock_instance):
     errorcode = ncc_client.NCCException.RESPONSE_ERROR
     mock_instance.side_effect = (ncc_client.NCCException(errorcode))