def test_delete_host(self): """Test delete host api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakes.FakeGetHostListResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.delete_host('fakeHostName') fake_params = { 'module': 'hosts', 'func': 'apply_delhost', 'host_name': 'fakeHostName', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = (('/cgi-bin/accessrights/accessrightsRequest.cgi?%s') % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_api_create_share_with_fail_response(self, fake_fail_response): """Test create share api with fail response.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response ] self.mock_object(time, 'sleep') self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.assertRaises(exception.ShareBackendException, self.driver.api_executor.create_share, share=self.share, pool_name='Storage Pool 1', create_share_name='fake_share_name', share_proto='NFS', qnap_deduplication=False, qnap_compression=True, qnap_thin_provision=True, qnap_ssd_cache=False)
def test_set_nfs_access(self, fakeGetHostListResponse): """Test get host list api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakeGetHostListResponse ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.set_nfs_access('fakeShareName', 'fakeAccess', 'fakeHostName') fake_params = { 'wiz_func': 'share_nfs_control', 'action': 'share_nfs_control', 'sharename': 'fakeShareName', 'access': 'fakeAccess', 'host_name': 'fakeHostName', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = (('/cgi-bin/priv/privWizard.cgi?%s') % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_get_snapshot_info_es(self): """Test get snapsho info api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakes.FakeSnapshotInfoResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.get_snapshot_info( volID='volId', snapshot_name='fakeSnapshotName') fake_params = { 'func': 'extra_get', 'volumeID': 'volId', 'snapshot_list': '1', 'snap_start': '0', 'snap_count': '100', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_clone_snapshot_api(self): """Test clone snapshot api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakes.FakeDeleteSnapshotResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.clone_snapshot('fakeSnapshotId', 'fakeNewShareName') fake_params = { 'func': 'clone_qsnapshot', 'by_vol': '1', 'snapshotID': 'fakeSnapshotId', 'new_name': 'fakeNewShareName', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/disk/snapshot.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_get_specific_volinfo(self): """Test get specific volume info api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakes.FakeSpecificVolInfoResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.get_specific_volinfo('fakeNo') fake_params = { 'store': 'volumeInfo', 'volumeID': 'fakeNo', 'func': 'extra_get', 'Volume_Info': '1', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/disk/disk_manage.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_api_delete_share(self): """Test delete share api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs_1_1_3(), fakes.FakeLoginResponse(), fakes.FakeDeleteShareResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.delete_share('fakeId') fake_params = { 'func': 'volume_mgmt', 'vol_remove': '1', 'volumeID': 'fakeId', 'stop_service': 'no', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/disk/disk_manage.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_get_snapshot_info_ts_with_fail_response( self, api, dict_parm, fake_fail_response, fake_basic_info): """Test get snapshot info api with fail response.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fake_basic_info, fakes.FakeLoginResponse(), fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response, fake_fail_response] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.mock_object(time, 'sleep') self.assertRaises( exception.ShareBackendException, eval(api), **dict_parm)
def test_edit_share_api(self): """Test edit share api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseTs_4_3_0(), fakes.FakeLoginResponse(), fakes.FakeCreateSnapshotResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') expect_share_dict = { "sharename": 'fakeVolId', "old_sharename": 'fakeVolId', "new_size": 100, "deduplication": False, "compression": True, "thin_provision": True, "ssd_cache": False, "share_proto": "NFS" } self.driver.api_executor.edit_share(expect_share_dict) fake_params = { 'wiz_func': 'share_property', 'action': 'share_property', 'sharename': 'fakeVolId', 'old_sharename': 'fakeVolId', 'dedup': 'off', 'compression': '1', 'thin_pro': '1', 'cache': '0', 'cifs_enable': '0', 'nfs_enable': '1', 'afp_enable': '0', 'ftp_enable': '0', 'hidden': '0', 'oplocks': '1', 'sync': 'always', 'recycle_bin': '1', 'recycle_bin_administrators_only': '0', 'sid': 'fakeSid', } if expect_share_dict.get('new_size'): fake_params['vol_size'] = '100GB' sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/priv/privWizard.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_create_share_api(self, fake_name): """Test create share api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseEs(), fakes.FakeLoginResponse(), fakes.FakeCreateShareResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.create_share(self.share, 'Storage Pool 1', fake_name, 'NFS') fake_params = { 'wiz_func': 'share_create', 'action': 'add_share', 'vol_name': fake_name, 'vol_size': '10' + 'GB', 'threshold': '80', 'dedup': 'off', 'compression': '1', 'thin_pro': '0', 'cache': '0', 'cifs_enable': '0', 'nfs_enable': '1', 'afp_enable': '0', 'ftp_enable': '0', 'encryption': '0', 'hidden': '0', 'oplocks': '1', 'sync': 'always', 'userrw0': 'admin', 'userrd_len': '0', 'userrw_len': '1', 'userno_len': '0', 'access_r': 'setup_users', 'path_type': 'auto', 'recycle_bin': '1', 'recycle_bin_administrators_only': '0', 'pool_name': 'Storage Pool 1', 'sid': 'fakeSid', } sanitized_params = self._sanitize_params(fake_params) fake_url = ('/cgi-bin/wizReq.cgi?%s' % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)
def test_get_snapshot_info_ts_api(self): """Test get snapshot info api.""" mock_http_connection = six.moves.http_client.HTTPConnection mock_http_connection.return_value.getresponse.side_effect = [ fakes.FakeLoginResponse(), fakes.FakeGetBasicInfoResponseTs_4_3_0(), fakes.FakeLoginResponse(), fakes.FakeSnapshotInfoResponse() ] self._do_setup('http://1.2.3.4:8080', '1.2.3.4', 'admin', 'qnapadmin', 'Storage Pool 1') self.driver.api_executor.get_snapshot_info( snapshot_name='fakeSnapshotName', lun_index='fakeLunIndex') fake_params = { 'func': 'extra_get', 'LUNIndex': 'fakeLunIndex', 'smb_snapshot_list': '1', 'smb_snapshot': '1', 'snapshot_list': '1', 'sid': 'fakeSid' } sanitized_params = self._sanitize_params(fake_params) fake_url = (('/cgi-bin/disk/snapshot.cgi?%s') % sanitized_params) expected_call_list = [ mock.call('GET', self.login_url), mock.call('GET', self.get_basic_info_url), mock.call('GET', self.login_url), mock.call('GET', fake_url) ] self.assertEqual( expected_call_list, mock_http_connection.return_value.request.call_args_list)