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_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_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_010_verify_SB_generate_multi_comp_dir_remove(self): """Validate multipe component directories are removed after SB generate.""" bundle_obj = SupportBundle.generate( comment=TestSupportBundle.sb_description, \ components=['csm', 'provisioner']) time.sleep(15) self.assertFalse( os.path.exists(f'{bundle_obj.bundle_path}/\ {bundle_obj.bundle_id}/{TestSupportBundle.node_name}/csm')) self.assertFalse( os.path.exists(f'{bundle_obj.bundle_path}/\ {bundle_obj.bundle_id}/{TestSupportBundle.node_name}/provisioner'))
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 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)