def test_volume(self): disks_count = lambda: len( self.vca_client.get_disks(self.vcloud_config['vdc'])) volume.creation_validation() disks_before = disks_count() volume.create_volume() if self.relationctx.source.node.properties['use_external_resource']: self.assertEqual(disks_before, disks_count()) else: self.assertEqual(disks_before + 1, disks_count()) self._attach_detach() volume.delete_volume() self.assertEqual(disks_before, disks_count())
def test_delete_volume(self): fake_client = self.generate_client() # external resource fake_ctx = cfy_mocks.MockCloudifyContext( node_id='test', node_name='test', properties={ 'use_external_resource': True, 'vcloud_config': { 'vdc': 'vdc_name' } } ) with mock.patch( 'vcloud_plugin_common.VcloudAirClient.get', mock.MagicMock(return_value=fake_client) ): volume.delete_volume(ctx=fake_ctx) # cant't add disk fake_ctx = cfy_mocks.MockCloudifyContext( node_id='test', node_name='test', properties={ 'use_external_resource': False, 'volume': { 'name': 'some-other', 'size': 11 }, 'vcloud_config': { 'vdc': 'vdc_name' } } ) with mock.patch( 'vcloud_plugin_common.VcloudAirClient.get', mock.MagicMock(return_value=fake_client) ): with self.assertRaises(cfy_exc.NonRecoverableError): volume.delete_volume(ctx=fake_ctx) fake_client.delete_disk.assert_called_with( 'vdc_name', 'some-other' ) # positive case fake_client.delete_disk = mock.MagicMock( return_value=( True, self.generate_task( vcloud_plugin_common.TASK_STATUS_SUCCESS ) ) ) with mock.patch( 'vcloud_plugin_common.VcloudAirClient.get', mock.MagicMock(return_value=fake_client) ): volume.delete_volume(ctx=fake_ctx)