예제 #1
0
 def test_get_disk_metrics(self, mock_login, mock_call, mock_disks):
     mock_login.return_value = None
     mock_call.return_value = [{
         'CMO_STATISTIC_DATA_LIST': '12,25',
         'CMO_STATISTIC_TIMESTAMP': 0
     }]
     mock_disks.return_value = [{
         'ID': '123',
         'TYPE': '100',
         'MODEL': 'disk',
         'SERIALNUMBER': '0'
     }]
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     metrics = rest_client.get_disk_metrics('', {'iops': {'unit': 'IOPS'}})
     mock_call.assert_called_with(
         "/performace_statistic/cur_statistic_data",
         None,
         'GET',
         log_filter_flag=True,
         params='CMO_STATISTIC_UUID=100:123&CMO_STATISTIC_DATA_ID_LIST=22&'
         'timeConversion=0&')
     expected_label = {
         'storage_id': '',
         'resource_type': 'disk',
         'resource_id': '123',
         'resource_name': 'disk:0',
         'type': 'RAW',
         'unit': 'IOPS',
     }
     self.assertEqual(metrics[0].name, 'iops')
     self.assertDictEqual(metrics[0].labels, expected_label)
     self.assertListEqual(list(metrics[0].values.values()), [12])
예제 #2
0
 def test_get_volumes(self, mock_login, mock_call):
     mock_login.return_value = None
     mock_call.return_value = RESP
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     data = rest_client.get_all_volumes()
     self.assertEqual(data['data']['data'], 'dummy')
     mock_call.assert_called_with("/lun", None, 'GET', log_filter_flag=True)
예제 #3
0
 def test_get_controller(self, mock_login, mock_call):
     mock_login.return_value = None
     mock_call.return_value = RESP
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     data = rest_client.get_controller()
     self.assertEqual(data['data'], 'dummy')
     mock_call.assert_called_with("/controller",
                                  log_filter_flag=True, method='GET')
예제 #4
0
    def test_reset_connection(self, mock_login):
        mock_login.return_value = None
        kwargs = ACCESS_INFO
        rest_client = RestClient(**kwargs)
        self.assertEqual(rest_client.rest_host, "10.0.0.1")
        self.assertEqual(rest_client.rest_port, 1234)

        mock_login.side_effect = exception.StorageBackendException
        with self.assertRaises(Exception) as exc:
            RestClient(**kwargs)
        self.assertIn('The credentials are invalid', str(exc.exception))
예제 #5
0
 def test_disable_metrics_collection(self, mock_login, mock_call):
     mock_login.return_value = None
     mock_call.return_value = RESP
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     data = rest_client.disable_metrics_collection()
     self.assertEqual(data['data'], 'dummy')
     mock_call.assert_called_with("/performance_statistic_switch",
                                  {'CMO_PERFORMANCE_SWITCH': '0'},
                                  log_filter_flag=True,
                                  method='PUT')
예제 #6
0
    def test_get_all_initiators(self, mock_login, mock_call):
        mock_login.return_value = None
        mock_call.side_effects = ["", "", ""]
        kwargs = ACCESS_INFO
        rest_client = RestClient(**kwargs)
        rest_client.get_all_initiators()
        call1 = call("/fc_initiator", None, 'GET', log_filter_flag=True)
        call2 = call("/iscsi_initiator", None, 'GET', log_filter_flag=True)
        call3 = call("/ib_initiator", None, 'GET', log_filter_flag=True)

        calls = [call1, call2, call3]
        mock_call.assert_has_calls(calls)
예제 #7
0
 def test_init(self, mock_rest):
     mock_resp = self._mock_response(json_data=RESP)
     mock_rest.return_value = mock_resp
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     self.assertEqual(rest_client.rest_host, "10.0.0.1")
     self.assertEqual(rest_client.rest_port, 1234)
     self.assertEqual(rest_client.session.headers['iBaseToken'], '112233')
예제 #8
0
 def test_configure_metrics_collection(self, mock_login, mock_call, mock_en,
                                       mock_di):
     mock_login.return_value = None
     mock_call.return_value = RESP
     mock_en.return_value = None
     mock_di.return_value = None
     kwargs = ACCESS_INFO
     rest_client = RestClient(**kwargs)
     rest_client.configure_metrics_collection()
     data = {
         "CMO_STATISTIC_ARCHIVE_SWITCH": 1,
         "CMO_STATISTIC_ARCHIVE_TIME": 300,
         "CMO_STATISTIC_AUTO_STOP": 0,
         "CMO_STATISTIC_INTERVAL": 60,
         "CMO_STATISTIC_MAX_TIME": 0
     }
     mock_call.assert_called_with("/performance_statistic_strategy",
                                  data,
                                  log_filter_flag=True,
                                  method='PUT')
예제 #9
0
    def test_get_storage(self, mock_login, mock_call):
        mock_login.return_value = None
        mock_call.return_value = RESP
        kwargs = ACCESS_INFO
        rest_client = RestClient(**kwargs)
        data = rest_client.get_storage()
        self.assertEqual(data['data'], 'dummy')

        mock_call.return_value = {"error": {"code": 0}}
        with self.assertRaises(Exception) as exc:
            rest_client.get_storage()
        self.assertIn('Exception from Storage Backend', str(exc.exception))

        mock_call.return_value['error']['code'] = 1
        with self.assertRaises(Exception) as exc:
            rest_client.get_storage()
        self.assertIn('Exception from Storage Backend', str(exc.exception))