Esempio n. 1
0
 def test_rest_request_no_session(self):
     """Test REST requests, no existing session available."""
     with mock.patch.object(
             self.rest,
             'establish_rest_session',
             return_value=pf.FakeRequestsSession()) as mck_sesh:
         self.rest.session = None
         __, __ = self.rest.rest_request('/fake_uri', 'GET', timeout=0.1)
         mck_sesh.assert_called_once()
Esempio n. 2
0
 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)
Esempio n. 3
0
 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)
Esempio n. 4
0
 def test_upload_file_success(self):
     """Test upload_file success scenario."""
     with mock.patch.object(self.conn.rest_client,
                            'establish_rest_session',
                            return_value=pf.FakeRequestsSession()):
         ref_response = {'success': True, 'message': 'OK'}
         response = self.common.upload_file(
             category=constants.SYSTEM,
             resource_level=constants.SETTINGS,
             resource_type=constants.IMPORT_FILE,
             form_data={'test_req': True})
         self.assertEqual(ref_response, response)
Esempio n. 5
0
 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
Esempio n. 6
0
 def test_download_file_success(self):
     """Test download_file success scenario."""
     with mock.patch.object(self.conn.rest_client,
                            'establish_rest_session',
                            return_value=pf.FakeRequestsSession()):
         request_body = {'test_req': True}
         response = self.common.download_file(
             category=constants.SYSTEM,
             resource_level=constants.SETTINGS,
             resource_type=constants.EXPORT_FILE,
             payload=request_body)
         self.assertIsInstance(response, pf.FakeResponse)
Esempio n. 7
0
 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)
Esempio n. 8
0
 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
Esempio n. 9
0
 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
Esempio n. 10
0
 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
Esempio n. 11
0
 def test_upload_file_value_error_exception(self):
     """Test upload_file value error, real call may have been successful."""
     with mock.patch.object(self.conn.rest_client,
                            'establish_rest_session',
                            return_value=pf.FakeRequestsSession()):
         with mock.patch.object(self.common,
                                'check_status_code_success',
                                side_effect=ValueError):
             ref_response = {'success': True, 'message': 'OK'}
             response = self.common.upload_file(
                 category=constants.SYSTEM,
                 resource_level=constants.SETTINGS,
                 resource_type=constants.IMPORT_FILE,
                 form_data={'test_req': True})
             self.assertEqual(ref_response, response)
Esempio n. 12
0
 def test_download_file_value_no_response_exception_catch(self):
     """Test download_file with no response, exception caught."""
     with mock.patch.object(self.conn.rest_client,
                            'establish_rest_session',
                            return_value=pf.FakeRequestsSession()):
         with mock.patch.object(self.common,
                                'check_status_code_success',
                                side_effect=ValueError):
             request_body = {'test_req': True}
             response = self.common.download_file(
                 category=constants.SYSTEM,
                 resource_level=constants.SETTINGS,
                 resource_type=constants.EXPORT_FILE,
                 payload=request_body)
             self.assertIsInstance(response, pf.FakeResponse)
Esempio n. 13
0
 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
Esempio n. 14
0
 def test_upload_file_fail_backend_exception(self):
     """Test upload_file fail with volume backend API exception."""
     with mock.patch.object(self.conn.rest_client,
                            'establish_rest_session',
                            return_value=pf.FakeRequestsSession()):
         with mock.patch.object(
                 self.conn.rest_client,
                 'file_transfer_request',
                 return_value=(pf.FakeResponse(
                     200,
                     return_object=dict(),
                     text=self.data.response_string_dict_fail), 200)):
             self.assertRaises(exception.VolumeBackendAPIException,
                               self.common.upload_file,
                               category=constants.SYSTEM,
                               resource_level=constants.SETTINGS,
                               resource_type=constants.IMPORT_FILE,
                               form_data={'test_req': True})
Esempio n. 15
0
 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)
Esempio n. 16
0
    def test_file_transfer_request_upload(self):
        """Test file_transfer_request download request."""
        with mock.patch.object(
                self.rest,
                'establish_rest_session',
                return_value=pf.FakeRequestsSession()) as mck_est:

            response, sc = self.rest.file_transfer_request(
                method=constants.POST,
                uri='/system/settings/exportfile',
                upload=True,
                form_data={'test_req': True})

            mck_est.assert_called_once_with(
                headers={
                    constants.ACCEPT_ENC: constants.APP_MPART,
                    constants.USER_AGENT: rest_requests.ua_details,
                    constants.APP_TYPE: self.rest.headers.get(
                        'application-type')
                })
            self.assertEqual(200, sc)
            self.assertEqual('OK', response.raw.reason)
Esempio n. 17
0
 def test_rest_request_other_exception(self):
     """Test REST other exception scenario."""
     self.rest.session = pf.FakeRequestsSession()
     self.assertRaises(exception.VolumeBackendAPIException,
                       self.rest.rest_request, '/fake_url', 'EXCEPTION')
Esempio n. 18
0
 def test_rest_request_ssl_exception(self):
     """Test REST SSL exception scenario."""
     self.rest.session = pf.FakeRequestsSession()
     self.assertRaises(requests.exceptions.SSLError, self.rest.rest_request,
                       '/fake_url', 'SSLERROR')
Esempio n. 19
0
 def test_rest_request_connection_exception(self):
     """Test REST HTTP error exception scenario."""
     self.rest.session = pf.FakeRequestsSession()
     self.assertRaises(requests.exceptions.HTTPError,
                       self.rest.rest_request, '/fake_url', 'HTTPERROR')
Esempio n. 20
0
 def test_rest_request_timeout_exception(self):
     """Test REST timeout exception scenario."""
     self.rest.session = pf.FakeRequestsSession()
     sc, msg = self.rest.rest_request('/fake_url', 'TIMEOUT')
     self.assertIsNone(sc)
     self.assertIsNone(msg)