def test_014_verify_SB_get_status_after_cluster_stop(self): """Validate SB get_status while cluster is down.""" cmd = "pcs cluster stop --all" cmd_proc = SimpleProcess(cmd) _, _, rc = cmd_proc.run() self.assertEqual(rc, 0) bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, components=['csm']) time.sleep(15) tar_file_name = f"{bundle_obj.bundle_id}_"\ f"{TestSupportBundle.node_name}.tar.gz" sb_file_path = f"{bundle_obj.bundle_path}/{bundle_obj.bundle_id}/"\ f"{TestSupportBundle.node_name}/{tar_file_name}" self.assertEqual(os.path.exists(sb_file_path), True) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) self.assertIsInstance(status, str) print(status) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Success') cmd = "pcs cluster start --all" cmd_proc = SimpleProcess(cmd) _, _, rc = cmd_proc.run() self.assertEqual(rc, 0) time.sleep(5)
def test_005status(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['wrong']) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) status = json.loads(status) self.assertEqual(status['status'], [])
def test_008_wrong_comp(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['util;csmm']) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Error')
def test_004status(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['csm']) time.sleep(5) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Success')
def test_006status(self): # TODO - Once all components are working this test case can be removed # Getting error because of some components dont have support.yaml and # empty support.yaml bundle_obj = SupportBundle.generate(comment=self.sb_description) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Error')
def test_012_verify_SB_get_status_error_single_invalid_comp(self): """Validate SB get_status error for single invalid component.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, components=['util;csm']) time.sleep(15) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Error')
def test_005_verify_SB_get_status_empty_invalid_comp(self): """Validate SB get_status empty for invalid component.""" # TODO - This test can be removed once bug(EOS-24882) is fixed bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, components=['wrong']) time.sleep(10) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) status = json.loads(status) self.assertEqual(status['status'], [])
def test_002_verify_cortx_SB_get_status_success(self): """Validate SB get_status success.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, target_path=target_path, bundle_id=generate_bundle_id(), config_url=TestSupportBundle.cluster_conf_path) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) self.assertIsInstance(status, str) self.assertIn("Successfully generated SB", status)
def test_003_verify_SB_get_status_success_single_comp(self): """Validate SB get_status success for single component.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, components=['utils']) time.sleep(15) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsNotNone(status) self.assertIsInstance(status, str) self.assertIsInstance(json.loads(status), dict) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Success')
def test_006_verify_SB_get_status_all_comp(self): """Validate SB get_status for all component.""" # TODO - Once all components are working this test case can be removed # Getting error because of some components dont have support.yaml and # empty support.yaml bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description) time.sleep(20) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) status = json.loads(status) if status['status']: self.assertEqual(status['status'][0]['result'], 'Error')
def test_009_verify_SB_generate_comp_dir_remove(self): """Validate component directories are removed after SB generate.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, components=['csm']) time.sleep(10) self.assertFalse(os.path.exists(f'{bundle_obj.bundle_path}/\ {bundle_obj.bundle_id}/{TestSupportBundle.node_name}/csm'))
def test_002generated_path(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['csm']) time.sleep(10) Conf.load('cluster_conf', 'json:///etc/cortx/cluster.conf') node_name = Conf.get('cluster_conf', 'cluster>srvnode-1') tar_file_name = f"{bundle_obj.bundle_id}_{node_name}.tar.gz" sb_file_path = f'{bundle_obj.bundle_path}/{bundle_obj.bundle_id}/{node_name}/{tar_file_name}' self.assertEqual(os.path.exists(sb_file_path), True)
def test_003_verify_SB_generated_path(self): """Validate SB generated path.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, target_path=target_path, bundle_id=generate_bundle_id(), config_url=TestSupportBundle.cluster_conf_path) bundle_path = bundle_obj.bundle_path.strip() tar_file_name = f"{bundle_path}/{bundle_obj.bundle_id}_{Conf.machine_id}.tar.gz" self.assertEqual(os.path.exists(tar_file_name), True)
def test_001generate(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['provisioner']) self.assertIsNotNone(bundle_obj) self.assertIsInstance(bundle_obj, Bundle) self.assertIsInstance(bundle_obj.bundle_id, str) self.assertIsInstance(bundle_obj.bundle_path, str) self.assertNotEqual(bundle_obj.bundle_id, '') self.assertNotEqual(bundle_obj.bundle_path, '') self.assertEqual(bundle_obj.comment, self.sb_description) self.assertEqual(os.path.exists(f'{bundle_obj.bundle_path}'), True)
def test_002_verify_SB_generated_path(self): """Validate SB generated path.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, \ components=['provisioner']) time.sleep(15) tar_file_name = f"{bundle_obj.bundle_id}_"\ f"{TestSupportBundle.node_name}.tar.gz" sb_file_path = f"{bundle_obj.bundle_path}/{bundle_obj.bundle_id}/"\ f"{TestSupportBundle.node_name}/{tar_file_name}" self.assertEqual(os.path.exists(sb_file_path), True)
def test_007_dir_remove(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['csm']) time.sleep(5) Conf.load('cluster_conf', 'json:///etc/cortx/cluster.conf', skip_reload=True) node_name = Conf.get('cluster_conf', 'cluster>srvnode-1') self.assertFalse( os.path.exists( f'{bundle_obj.bundle_path}/{bundle_obj.bundle_id}/{node_name}/csm' ))
def test_001_verify_SB_generate_single_comp(self): """Validate SB generate for single component.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, \ components=['provisioner']) self.assertIsNotNone(bundle_obj) self.assertIsInstance(bundle_obj, Bundle) self.assertIsInstance(bundle_obj.bundle_id, str) self.assertIsInstance(bundle_obj.bundle_path, str) self.assertNotEqual(bundle_obj.bundle_id, '') self.assertNotEqual(bundle_obj.bundle_path, '') self.assertEqual(bundle_obj.comment, TestSupportBundle.sb_description) self.assertEqual(os.path.exists(f'{bundle_obj.bundle_path}'), True)
def test_001_verify_SB_generate_single_comp(self): """Validate SB generate.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, target_path=target_path, bundle_id=generate_bundle_id(), config_url=TestSupportBundle.cluster_conf_path) self.assertIsNotNone(bundle_obj) self.assertIsInstance(bundle_obj, Bundle) self.assertIsInstance(bundle_obj.bundle_id, str) self.assertIsInstance(bundle_obj.bundle_path, str) self.assertNotEqual(bundle_obj.bundle_id, '') self.assertNotEqual(bundle_obj.bundle_path, '') self.assertEqual(bundle_obj.comment, TestSupportBundle.sb_description)
def generate(args): """Generates support bundle for specified components.""" from cortx.utils.support_framework.errors import BundleError if not args.comment: # no comment provided raise BundleError("Please provide comment, Why you are generating \ Support Bundle!") comment = args.comment[0] components = args.component[0].split(';') if args.component else [] bundle_obj = SupportBundle.generate(comment=comment, \ components=components) display_string_len = len(bundle_obj.bundle_id) + 4 response_msg = ( f"Please use the below bundle id for checking the status of support bundle." f"\n{'-' * display_string_len}" f"\n| {bundle_obj.bundle_id} |" f"\n{'-' * display_string_len}" f"\nPlease Find the file on -> {bundle_obj.bundle_path} .\n") return response_msg
def test_013_verify_SB_generate_after_elasticsearch_service_stop(self): """Validate SB generate while elasticsearch service is down.""" cmd = "systemctl stop elasticsearch" cmd_proc = SimpleProcess(cmd) _, _, rc = cmd_proc.run() self.assertEqual(rc, 0) bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, \ components=['provisioner']) time.sleep(15) tar_file_name = f"{bundle_obj.bundle_id}_"\ f"{TestSupportBundle.node_name}.tar.gz" sb_file_path = f"{bundle_obj.bundle_path}/{bundle_obj.bundle_id}/"\ f"{TestSupportBundle.node_name}/{tar_file_name}" self.assertEqual(os.path.exists(sb_file_path), True) cmd = "systemctl start elasticsearch" cmd_proc = SimpleProcess(cmd) _, _, rc = cmd_proc.run() self.assertEqual(rc, 0) ServiceV().validate('isrunning', ['elasticsearch'])
def generate(args): """Generates support bundle for specified components.""" from cortx.utils.support_framework.errors import BundleError message = args.message[0] if not message: raise BundleError(errno.EINVAL, "Invalid or Empty message string. %s", message) bundle_id = args.bundle_id[0] bundle_id = bundle_id.strip() if not bundle_id: raise BundleError(errno.EINVAL, "Invalid Bundle ID to generate support bundle!") regex = re.compile('[@!#$%^&*()<>?/\|}{~:]') if (regex.search(bundle_id) != None): raise BundleError(errno.EINVAL, ("Invalid Bundle ID," "No special characters allowed in Bundle ID.")) path = args.location duration = args.duration size_limit = args.size_limit.upper() # size_limit should be in units - KB, MB or GB. units = ['KB', 'MB', 'GB'] sb_size_unit = any(unit in size_limit for unit in units) if not sb_size_unit: raise BundleError( errno.EINVAL, "Support Bundle size limit should be in KB/MB/GB units.\ Size unit: %s", size_limit) # Collect all [binlogs, coredumps, stacktrace] if "--all true" is passed all_logs = args.all if all_logs: binlogs = coredumps = stacktrace = True else: binlogs = args.binlogs coredumps = args.coredumps stacktrace = args.stacktrace components = args.modules config_url = args.cluster_conf_path[0] if 'file://' not in path: raise BundleError( errno.EINVAL, "Invalid target path specified.\n" "Target path should be in file format.\n" "For example:-\n" "support_bundle generate -m 'test_cortx' -b 'abc' -t file:///var/cortx/support_bundle\n" ) path = path.split('//')[1] os.makedirs(const.SB_PATH, exist_ok=True) bundle_obj = SupportBundle.generate(comment=message, target_path=path, bundle_id=bundle_id, duration=duration, config_url=config_url, size_limit=size_limit, binlogs=binlogs, coredumps=coredumps, stacktrace=stacktrace, components=components) display_string_len = len(bundle_obj.bundle_id) + 4 response_msg = ( f"Please use the below bundle id for checking the status of support bundle." f"\n{'-' * display_string_len}" f"\n| {bundle_obj.bundle_id} |" f"\n{'-' * display_string_len}" f"\nPlease Find the file on -> {bundle_obj.bundle_path} .\n") return response_msg
def get_status(args): """Get status of generated support bundle.""" bundle_id = args.bundle_id[0] if args.bundle_id else None status = SupportBundle.get_status(bundle_id=bundle_id) return status
def test_003status(self): bundle_obj = SupportBundle.generate(comment=self.sb_description, components=['csm']) status = SupportBundle.get_status(bundle_id=bundle_obj.bundle_id) self.assertIsInstance(status, str) self.assertIsInstance(json.loads(status), dict)