def test_write_binary_data_to_file_no_dir(self): """Test write_binary_data_to_file no directory path.""" response, temp_dir_path = str(), str() try: temp_u4v_conn = univmax_conn.U4VConn() dummy_data = temp_u4v_conn.common.download_file( category=constants.SYSTEM, resource_level=constants.SYMMETRIX, resource_level_id=temp_u4v_conn.array_id, resource_type=constants.AUDIT_LOG_RECORD, resource=constants.EXPORT_FILE, payload={constants.AUDIT_LOG_FILENAME: 'ci_test'}) self.assertTrue(dummy_data) temp_dir_path = Path.cwd() temp_filename = Path('ci_test_dummy_data') temp_suffix = constants.PDF_SUFFIX temp_pdf_filename = temp_filename.with_suffix(temp_suffix) temp_full_path = Path.joinpath(temp_dir_path, temp_pdf_filename) response = file_handler.write_binary_data_to_file( data=dummy_data, file_extension=temp_suffix, file_name=str(temp_filename)) self.assertTrue(dummy_data) self.assertEqual(str(temp_full_path), str(response)) self.addCleanup(self.cleanup_files, temp_file=str(response)) # If there are any exceptions raised ensure cleanup is carried out on # changes to PyU4V.conf except Exception as e: self.addCleanup(self.cleanup_files, temp_file=str(response)) raise Exception('Test failed with exception: {msg}'.format(msg=e))
def test_conf_in_current_directory(self): """Test config handler with PyU4V in current directory.""" # Skip test condition if self.skip_config_ci: self.skipTest(reason='PyU4V.conf not in ~/.PyU4V/') # Set the config file temporary name and initialise temp config file hidden_conf = os.path.normpath( '{dir}/__PyU4V.conf'.format(dir=self.conf_dir)) temp_file = str() try: # Make copy of PyU4V.conf to current directory temp_file = shutil.copy(self.conf_file, os.getcwd()) # Rename PyU4V for this test to ensure it isn't loaded by default os.rename(self.conf_file, hidden_conf) # Create U4VConn using temporary PyU4V.conf in current dir temp_u4v_conn = univmax_conn.U4VConn() # Perform basic request for Unisphere version, assert successful test_request = temp_u4v_conn.common.get_uni_version() self.assertTrue(test_request) # Cleanup self.addCleanup(self.cleanup_files, pyu4v_orig=(self.conf_file, hidden_conf), temp_file=temp_file) # If there are any exceptions raised ensure cleanup is carried out on # changes to PyU4V.conf except Exception as e: self.addCleanup(self.cleanup_files, pyu4v_orig=(self.conf_file, hidden_conf), temp_file=temp_file) raise Exception('Test failed with exception: {msg}'.format(msg=e))
def test_init_config_verify_exception(self): """Test initialisation of U4VConn with SSL verification set.""" config_file, config_dir = pf.FakeConfigFile.create_fake_config_file( verify_key=False) univmax_conn.file_path = config_file with mock.patch.object( rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): conn = univmax_conn.U4VConn() self.assertTrue(conn.rest_client.verify_ssl) pf.FakeConfigFile.delete_fake_config_file(config_file, config_dir)
def test_init_config_file_no_array_set(self): """Test initialisation of U4VConn with no array set.""" config_file, config_dir = pf.FakeConfigFile.create_fake_config_file( array=None) univmax_conn.file_path = config_file with mock.patch.object( rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): conn = univmax_conn.U4VConn() self.assertIsNone(conn.array_id) pf.FakeConfigFile.delete_fake_config_file(config_file, config_dir)
def setUp(self): """Setup.""" super(PyU4VUnivmaxWLPTest, self).setUp() self.data = pcd.CommonData() self.conf_file, self.conf_dir = ( pf.FakeConfigFile.create_fake_config_file()) univmax_conn.file_path = self.conf_file with mock.patch.object(rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): self.conn = univmax_conn.U4VConn(array_id=self.data.array) self.wlp = self.conn.wlp
def setUp(self): """Set up the test class.""" super(TestMigrate, self).setUp() self.data = pcd.CommonData() self.conf_file, self.conf_dir = ( pf.FakeConfigFile.create_fake_config_file()) univmax_conn.file_path = self.conf_file with mock.patch.object(rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): conn = univmax_conn.U4VConn() self.utils = migrate_utils.MigrateUtils(conn)
def setUp(self): """Setup.""" super(PyU4VUnivmaxConnTest, self).setUp() self.data = pcd.CommonData() with mock.patch.object( rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): self.conn = univmax_conn.U4VConn( username='******', password='******', server_ip='10.0.0.75', port='8443', verify=False, interval=5, retries=200, array_id=self.data.array, application_type='pyu4v') self.common = self.conn.common self.common.interval = 1 self.common.retries = 1
def setUp(self): """setUp.""" super(PyU4VCommonTest, self).setUp() self.data = pcd.CommonData() self.conf_file, self.conf_dir = ( pf.FakeConfigFile.create_fake_config_file()) univmax_conn.file_path = self.conf_file with mock.patch.object(rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): self.conn = univmax_conn.U4VConn() self.common = self.conn.common self.common.interval = 1 self.common.retries = 1
def setUp(self): """Setup.""" super(PyU4VMetroDRTest, self).setUp() self.data = pcd.CommonData() self.conf_file, self.conf_dir = ( pf.FakeConfigFile.create_fake_config_file()) univmax_conn.file_path = self.conf_file with mock.patch.object( rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): self.conn = univmax_conn.U4VConn(array_id=self.data.array) self.provisioning = self.conn.provisioning self.replication = self.conn.replication self.metro_dr = self.conn.metro_dr
def setUp(self): """setUp.""" super(PyU4VPerformanceTest, self).setUp() self.p_data = pd.PerformanceData() self.conf_file, self.conf_dir = ( pf.FakeConfigFile.create_fake_config_file()) univmax_conn.file_path = self.conf_file with mock.patch.object(rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): self.conn = univmax_conn.U4VConn(array_id=self.p_data.array) self.perf = self.conn.performance self.rt = self.perf.real_time self.common = self.conn.common self.time_now = int(time.time()) * 1000
def test_init_config_file_all_settings(self): """Test initialisation of U4VConn using all required settings.""" config_file, config_dir = pf.FakeConfigFile.create_fake_config_file( verify=True) univmax_conn.file_path = config_file with mock.patch.object(rest_requests.RestRequests, 'establish_rest_session', return_value=pf.FakeRequestsSession()): conn = univmax_conn.U4VConn() self.assertEqual(pcd.CommonData.array, conn.array_id) self.assertIsInstance(conn.rest_client, rest_requests.RestRequests) self.assertEqual('smc', conn.rest_client.username) self.assertEqual('smc', conn.rest_client.password) self.assertTrue(conn.rest_client.verify_ssl) self.assertEqual('https://10.0.0.75:8443/univmax/restapi', conn.rest_client.base_url) self.assertEqual(pcd.CommonData.remote_array, conn.remote_array) pf.FakeConfigFile.delete_fake_config_file(config_file, config_dir)
def test_conf_in_user_directory(self): """Test config handler with PyU4V in user specified directory.""" # Skip test condition if self.skip_config_ci: self.skipTest(reason='PyU4V.conf not in ~/.PyU4V/') # Set the config file temporary name and initialise temp config file # and temp directory hidden_conf = os.path.normpath( '{dir}/__PyU4V.conf'.format(dir=self.conf_dir)) # Initialise path strings for temporary file and directory temp_file, temp_dir = str(), str() try: # Create a temporary directory temp_dir = tempfile.mkdtemp() # Copy source PyU4V.conf to new temporary directory temp_file = shutil.copy(self.conf_file, temp_dir) # Rename source PyU4V.conf so it cannot be loaded by default os.rename(self.conf_file, hidden_conf) # Set the filepath to PyU4V.conf in the temporary directory univmax_conn.file_path = temp_file # Initialise U4VConn and temp_u4v_conn = univmax_conn.U4VConn() # Perform basic request for Unisphere version, assert successful test_request = temp_u4v_conn.common.get_uni_version() self.assertTrue(test_request) # Cleanup # Reset path to PyU4V.conf to None univmax_conn.file_path = None self.addCleanup(self.cleanup_files, pyu4v_orig=(self.conf_file, hidden_conf), temp_file=temp_file, temp_dir=temp_dir) # If there are any exceptions raised ensure cleanup is carried out on # changes to PyU4V.conf except Exception as e: self.addCleanup(self.cleanup_files, pyu4v_orig=(self.conf_file, hidden_conf), temp_file=temp_file, temp_dir=temp_dir) raise Exception('Test failed with exception: {msg}'.format(msg=e))
The script migrates volumes from the old SMI-S Masking view to the new REST Masking view used from Pike onwards """ from __future__ import print_function from builtins import input import sys from PyU4V.tools.openstack import migrate_utils from PyU4V import univmax_conn sys.path.append('../../..') sys.path.append('.') conn = univmax_conn.U4VConn() utils = migrate_utils.MigrateUtils(conn) utils.smart_print( '********************************************************************', migrate_utils.DEBUG) utils.smart_print( '*** Welcome to the migration script for the VMAX/PowerMax driver ***', migrate_utils.DEBUG) utils.smart_print( '*** to migrate from SMI-S masking view to REST masking view. ***', migrate_utils.DEBUG) utils.smart_print( '*** This is recommended if you intend using live migration to ***', migrate_utils.DEBUG) utils.smart_print(
def setup_credentials(self): """Set REST credentials.""" self.conn = univmax_conn.U4VConn() self.assertTrue(self.conn.rest_client.headers.get('user-agent'))