def test_migration_start(self, mock_horizon_messages_success): self.mock_object( api, "share_network_list", mock.Mock(return_value=[ base.FakeEntity('sn1_id', 'sn1_name'), base.FakeEntity('sn2_id', 'sn2_name') ])) self.mock_object( api, "share_type_list", mock.Mock(return_value=[ base.FakeEntity('st1_id', 'st1_name'), base.FakeEntity('st2_id', 'st2_name') ])) self.mock_object( api, "pool_list", mock.Mock(return_value=[ base.FakeEntity('ubuntu@beta#BETA', 'ubuntu@beta#BETA'), base.FakeEntity('ubuntu@alpha#ALPHA', 'ubuntu@alpha#ALPHA') ])) form = forms.MigrationStart(self.request, **self._get_initial()) data = { 'force_host_assisted_migration': False, 'writable': True, 'preserve_metadata': True, 'preserve_snapshots': True, 'nondisruptive': True, 'new_share_network': 'fake_net_id', 'new_share_type': 'fake_type_id', 'host': 'fake_host', } result = form.handle(self.request, data) self.assertTrue(result) mock_horizon_messages_success.assert_called_once_with( self.request, mock.ANY) api.share_network_list.assert_called_once_with(mock.ANY) api.share_type_list.assert_called_once_with(mock.ANY) api.pool_list.assert_called_once_with(mock.ANY)
def test_migration_forms_open_form_successfully(self, method): share = test_data.share url = reverse('horizon:admin:shares:' + method, args=[share.id]) self.mock_object(api_manila, "share_get", mock.Mock(return_value=share)) self.mock_object(api_manila, method) if method == 'migration_start': self.mock_object( api_manila, "share_network_list", mock.Mock(return_value=[ test.FakeEntity('sn1_id', 'sn1_name'), test.FakeEntity('sn2_id', 'sn2_name') ])) self.mock_object( api_manila, "share_type_list", mock.Mock(return_value=[ test.FakeEntity('st1_id', 'st1_name'), test.FakeEntity('st2_id', 'st2_name') ])) self.mock_object( api_manila, "pool_list", mock.Mock(return_value=[ test.FakeEntity('ubuntu@beta#BETA', 'ubuntu@beta#BETA'), test.FakeEntity('ubuntu@alpha#ALPHA', 'ubuntu@alpha#ALPHA') ])) res = self.client.get(url) api_manila.share_get.assert_called_once_with(mock.ANY, share.id) self.assertFalse(getattr(api_manila, method).called) self.assertEqual(res.status_code, 200) self.assertTemplateUsed(res, 'admin/shares/' + method + '.html') if method == 'migration_start': api_manila.share_network_list.assert_called_once_with(mock.ANY) api_manila.share_type_list.assert_called_once_with(mock.ANY) api_manila.pool_list.assert_called_once_with(mock.ANY)
def test_migration_start_post(self, exc): share = test_data.share url = reverse('horizon:admin:shares:migration_start', args=[share.id]) sn_choices = [ test.FakeEntity('sn1_id', 'sn1_name'), test.FakeEntity('sn2_id', 'sn2_name') ] st_choices = [ test.FakeEntity('st1_id', 'st1_name'), test.FakeEntity('st2_id', 'st2_name') ] dest_choices = [ test.FakeEntity('ubuntu@beta#BETA', 'ubuntu@beta#BETA'), test.FakeEntity('ubuntu@alpha#ALPHA', 'ubuntu@alpha#ALPHA') ] formData = { 'share_id': share.id, 'name': share.name, 'host': 'ubuntu@alpha#ALPHA', 'writable': True, 'preserve_metadata': True, 'preserve_snapshots': True, 'force_host_assisted_migration': True, 'nondisruptive': True, 'new_share_network': 'sn2_id', 'new_share_type': 'st2_id', } self.mock_object(api_manila, "share_get", mock.Mock(return_value=share)) self.mock_object(api_manila, "migration_start", mock.Mock(side_effect=exc)) self.mock_object(api_manila, "share_network_list", mock.Mock(return_value=sn_choices)) self.mock_object(api_manila, "share_type_list", mock.Mock(return_value=st_choices)) self.mock_object(api_manila, "pool_list", mock.Mock(return_value=dest_choices)) res = self.client.post(url, formData) api_manila.share_get.assert_called_once_with(mock.ANY, share.id) api_manila.migration_start.assert_called_once_with( mock.ANY, formData['share_id'], dest_host=formData['host'], force_host_assisted_migration=( formData['force_host_assisted_migration']), writable=formData['writable'], preserve_metadata=formData['preserve_metadata'], preserve_snapshots=formData['preserve_snapshots'], nondisruptive=formData['nondisruptive'], new_share_network_id=formData['new_share_network'], new_share_type_id=formData['new_share_type']) api_manila.share_network_list.assert_called_once_with(mock.ANY) api_manila.share_type_list.assert_called_once_with(mock.ANY) api_manila.pool_list.assert_called_once_with(mock.ANY) self.assertEqual(302, res.status_code) self.assertTemplateNotUsed(res, 'admin/shares/migration_start.html') self.assertRedirectsNoFollow(res, INDEX_URL)