def test_list_storage_pools(self, mock_pool): RestHandler.login = mock.Mock(return_value=None) mock_pool.return_value = GET_ALL_POOLS pool = UnityStorDriver(**ACCESS_INFO).list_storage_pools(context) self.assertDictEqual(pool[0], pool_result[0]) mock_pool.return_value = GET_ALL_ABNORMAL_POOLS pool = UnityStorDriver(**ACCESS_INFO).list_storage_pools(context) self.assertDictEqual(pool[0], pool_abnormal_result[0])
def test_parse_alert(self): RestHandler.login = mock.Mock(return_value=None) trap = UnityStorDriver(**ACCESS_INFO).parse_alert(context, TRAP_INFO) trap['occur_time'] = int(1605852610000) self.assertEqual(trap, trap_result) trap = UnityStorDriver(**ACCESS_INFO).parse_alert( context, TRAP_NOT_IN_MAPPPING_INFO) trap['occur_time'] = int(1605852610000) self.assertEqual(trap, trap_not_in_mapping_result)
def test_get_storage(self, mock_version, mock_capa, mock_base): RestHandler.login = mock.Mock(return_value=None) mock_version.return_value = GET_SOFT_VERSION mock_capa.return_value = GET_CAPACITY mock_base.return_value = GET_STORAGE_ABNORMAL storage = UnityStorDriver(**ACCESS_INFO).get_storage(context) self.assertDictEqual(storage, storage_abnormal_result) mock_base.return_value = GET_STORAGE_NORMAL storage = UnityStorDriver(**ACCESS_INFO).get_storage(context) self.assertDictEqual(storage, storage_normal_result)
def test_list_ports(self, mock_fc, mock_ip, mock_eth): RestHandler.login = mock.Mock(return_value=None) mock_eth.return_value = GET_ALL_ETHPORTS mock_ip.return_value = GET_ALL_IP mock_fc.return_value = GET_ALL_FCPORTS port = UnityStorDriver(**ACCESS_INFO).list_ports(context) self.assertEqual(port, port_result)
def test_list_shares(self, mock_file, mock_qtree, mock_cifs, mock_nfs): RestHandler.login = mock.Mock(return_value=None) mock_cifs.return_value = GET_ALL_CIFSSHARE mock_qtree.return_value = GET_ALL_QTREE mock_nfs.return_value = GET_ALL_NFSSHARE mock_file.return_value = GET_ALL_FILESYSTEMS share = UnityStorDriver(**ACCESS_INFO).list_shares(context) self.assertEqual(share, share_result)
def test_call_and_login(self, mock_token): with self.assertRaises(Exception) as exc: mock_token.return_value = mock.MagicMock(status_code=401, text='Unauthorized') UnityStorDriver(**ACCESS_INFO).rest_handler.login() self.assertEqual('Invalid username or password.', str(exc.exception)) with self.assertRaises(Exception) as exc: mock_token.return_value = mock.MagicMock(status_code=401, text='Forbidden') UnityStorDriver(**ACCESS_INFO).rest_handler.login() self.assertEqual('Invalid ip or port.', str(exc.exception)) with self.assertRaises(Exception) as exc: mock_token.return_value = mock.MagicMock(status_code=503) UnityStorDriver(**ACCESS_INFO).rest_handler.call('') self.assertIn('Exception from Storage Backend', str(exc.exception)) RestHandler.login = mock.Mock(return_value=None) mock_token.return_value = mock.MagicMock(status_code=401) UnityStorDriver(**ACCESS_INFO).rest_handler.call('')
def test_list_quotas(self, mock_user, mock_qtree): RestHandler.login = mock.Mock(return_value=None) mock_user.return_value = GET_ALL_USERQUOTA mock_qtree.return_value = GET_ALL_QTREE quota = UnityStorDriver(**ACCESS_INFO).list_quotas(context) self.assertEqual(quota, quota_result)
def test_list_qtrees(self, mock_qtree): RestHandler.login = mock.Mock(return_value=None) mock_qtree.return_value = GET_ALL_QTREE qtree = UnityStorDriver(**ACCESS_INFO).list_qtrees(context) self.assertEqual(qtree, qtree_result)
def test_list_filesystems(self, mock_filesystem): RestHandler.login = mock.Mock(return_value=None) mock_filesystem.return_value = GET_ALL_FILESYSTEMS file = UnityStorDriver(**ACCESS_INFO).list_filesystems(context) self.assertEqual(file, filesystem_result)
def test_list_disks(self, mock_disk): RestHandler.login = mock.Mock(return_value=None) mock_disk.return_value = GET_ALL_DISKS disk = UnityStorDriver(**ACCESS_INFO).list_disks(context) self.assertEqual(disk, disk_result)
def test_list_controllers(self, mock_controller): RestHandler.login = mock.Mock(return_value=None) mock_controller.return_value = GET_ALL_CONTROLLERS controller = UnityStorDriver(**ACCESS_INFO).list_controllers(context) self.assertEqual(controller, controller_result)
def test_get_rest_info(self, mock_rest): RestHandler.login = mock.Mock(return_value=None) mock_rest.return_value = mock.MagicMock(status_code=200) UnityStorDriver(**ACCESS_INFO).rest_handler.get_rest_info('') self.assertEqual(mock_rest.call_count, 1)
def test_list_alerts(self, mock_alert): RestHandler.login = mock.Mock(return_value=None) mock_alert.side_effect = [GET_ALL_ALERTS, GET_ALL_ALERTS_NULL] alert = UnityStorDriver(**ACCESS_INFO).list_alerts(context) alert_result[0]['occur_time'] = alert[0]['occur_time'] self.assertEqual(alert[0], alert_result[0])
def test_clear_alert(self, mock_remove): RestHandler.login = mock.Mock(return_value=None) alert_id = 101 UnityStorDriver(**ACCESS_INFO).clear_alert(context, alert_id) self.assertEqual(mock_remove.call_count, 1)
def test_list_volumes(self, mock_lun): RestHandler.login = mock.Mock(return_value=None) mock_lun.side_effect = [GET_ALL_LUNS, GET_ALL_LUNS_NULL] volume = UnityStorDriver(**ACCESS_INFO).list_volumes(context) self.assertDictEqual(volume[0], volume_result[0])