def test_parsed_json_match_parsed_csv(self): """Output generated by: JSON: LANG=en_US.UTF-8 hammer -v -u admin -p changeme --output=json gpg info --id="160" --organization-id="1003" CSV: LANG=en_US.UTF-8 hammer -v -u admin -p changeme --output=csv gpg info --id="160" --organization-id="1003" """ json_output = """{ "ID": 160, "Name": "QUWTHo0WzF", "Organization": "ANtbiU", "Content": "qJxB1FX1UrssYiGGhRcZDF9eY8U" } """ csv_ouput_lines = [ "ID,Name,Organization,Content", "160,QUWTHo0WzF,ANtbiU,qJxB1FX1UrssYiGGhRcZDF9eY8U", ] assert hammer.parse_json(json_output) == hammer.parse_csv( csv_ouput_lines)[0]
def command( cmd, hostname=None, output_format=None, username=None, password=None, timeout=None, port=22, ): """Executes SSH command(s) on remote hostname. kwargs are passed through to get_connection :param str cmd: The command to run :param str output_format: json, csv or None :param int timeout: Time to wait for the ssh command to finish. :param connection_timeout: Time to wait for establishing the connection. """ client = get_client( hostname=hostname, username=username, password=password, port=port, ) result = client.execute(cmd, timeout=timeout) if output_format and result.status == 0: if output_format == 'csv': result.stdout = hammer.parse_csv( result.stdout) if result.stdout else {} if output_format == 'json': result.stdout = hammer.parse_json( result.stdout) if result.stdout else None return result
def __init__( self, stdout=None, stderr=None, return_code=0, output_format=None): self.stdout = stdout self.stderr = stderr self.return_code = return_code self.output_format = output_format # Does not make sense to return suspicious output if ($? <> 0) if output_format and self.return_code == 0: if output_format == 'csv': self.stdout = hammer.parse_csv(stdout) if stdout else {} if output_format == 'json': self.stdout = hammer.parse_json(stdout) if stdout else None
def test_parsed_json_match_parsed_csv(self): """ Output generated by: JSON: LANG=en_US.UTF-8 hammer -v -u admin -p changeme --output=json gpg info --id="160" --organization-id="1003" CSV: LANG=en_US.UTF-8 hammer -v -u admin -p changeme --output=csv gpg info --id="160" --organization-id="1003" """ json_output = u"""{ "ID": 160, "Name": "QUWTHo0WzF", "Organization": "ANtbiU", "Content": "qJxB1FX1UrssYiGGhRcZDF9eY8U" } """ csv_ouput_lines = [u"ID,Name,Organization,Content", u"160,QUWTHo0WzF,ANtbiU,qJxB1FX1UrssYiGGhRcZDF9eY8U" ] self.assertEqual(hammer.parse_json(json_output), hammer.parse_csv(csv_ouput_lines)[0])
def test_parse_json_list(self): """Can parse a list in json""" assert hammer.parse_json('["item1", "item2"]') == ['item1', 'item2']
def test_parse_json(self): """Output generated with: hammer -u admin -p changeme --output json content-view info --id 1""" output = """{ "ID": 1, "Name": "Default Organization View", "Label": "Default_Organization_View", "Composite": false, "Description": null, "Content Host Count": 0, "Organization": "Default Organization", "Yum Repositories": { }, "Container Image Repositories": { }, "OSTree Repositories": { }, "Puppet Modules": { }, "Lifecycle Environments": { "1": { "ID": 1, "Name": "Library" } }, "Versions": { "1": { "ID": 1, "Version": "1.0", "Published": "2016-07-05 17:35:33 UTC" } }, "Components": { }, "Activation Keys": { } }""" assert hammer.parse_json(output) == { 'puppet-modules': {}, 'description': None, 'versions': { '1': { 'version': '1.0', 'id': '1', 'published': '2016-07-05 17:35:33 UTC' } }, 'composite': False, 'ostree-repositories': {}, 'label': 'Default_Organization_View', 'activation-keys': {}, 'container-image-repositories': {}, 'components': {}, 'organization': 'Default Organization', 'yum-repositories': {}, 'lifecycle-environments': { '1': { 'id': '1', 'name': 'Library' } }, 'id': '1', 'content-host-count': '0', 'name': 'Default Organization View', }
def test_positive_rename_satellite(self, module_org, module_product, destructive_sat): """run katello-change-hostname on Satellite server :id: 9944bfb1-1440-4820-ada8-2e219f09c0be :setup: Satellite server with synchronized rh and custom repos and with a registered host :steps: 1. Rename Satellite using katello-change-hostname 2. Do basic checks for hostname change (hostnamctl) 3. Run some existence tests, as in backup testing 4. Verify certificates were properly recreated, check for instances of old hostname in etc/foreman-installer/scenarios.d/ 5. Check for updated repo urls, installation media paths, updated internal capsule 6. Check usability of entities created before rename: resync repos, republish CVs and re-register hosts 7. Create new entities (run end-to-end test from robottelo) :BZ: 1469466, 1897360, 1925616 :expectedresults: Satellite hostname is successfully updated and the server functions correctly :CaseImportance: Critical :CaseAutomation: Automated """ username = settings.server.admin_username password = settings.server.admin_password old_hostname = destructive_sat.execute('hostname').stdout new_hostname = f'new-{old_hostname}' # create installation medium with hostname in path medium_path = f'http://{old_hostname}/testpath-{gen_string("alpha")}/os/' medium = entities.Media(organization=[module_org], path_=medium_path).create() repo = entities.Repository(product=module_product, name='testrepo').create() result = destructive_sat.execute( f'satellite-change-hostname {new_hostname} -y -u {username} -p {password}', timeout=1200000, ) assert result.status == 0, 'unsuccessful rename' assert BCK_MSG in result.stdout # services running after rename? result = destructive_sat.execute('hammer ping') assert result.status == 0, 'services did not start properly' # basic hostname check result = destructive_sat.execute('hostname') assert result.status == 0 assert new_hostname in result.stdout, 'hostname left unchanged' # check default capsule result = destructive_sat.execute( f'hammer -u {username} -p {password} --output json capsule info --name {new_hostname}' ) assert result.status == 0, 'internal capsule not renamed correctly' assert hammer.parse_json(result.stdout)['url'] == f"https://{new_hostname}:9090" # check old consumer certs were deleted result = destructive_sat.execute(f'rpm -qa | grep ^{old_hostname}') assert result.status == 1, 'old consumer certificates not removed' # check new consumer certs were created result = destructive_sat.execute(f'rpm -qa | grep ^{new_hostname}') assert result.status == 0, 'new consumer certificates not created' # check if installation media paths were updated result = destructive_sat.execute( f'hammer -u {username} -p {password} --output json medium info --id {medium.id}' ) assert result.status == 0 assert new_hostname in hammer.parse_json(result.stdout)['path'] # check answer file for instances of old hostname ans_f = '/etc/foreman-installer/scenarios.d/satellite-answers.yaml' result = destructive_sat.execute(f'grep " {old_hostname}" {ans_f}') assert result.status == 1, 'old hostname was not correctly replaced in answers.yml' # check repository published at path result = destructive_sat.execute( f'hammer -u {username} -p {password} --output json repository info --id {repo.id}' ) assert result.status == 0 assert ( new_hostname in hammer.parse_json(result.stdout)['published-at'] ), 'repository published path not updated correctly' # check for any other occurences of old hostname result = destructive_sat.execute(f'grep " {old_hostname}" /etc/* -r') assert result.status == 1, 'there are remaining instances of the old hostname' repo.sync() cv = entities.ContentView(organization=module_org).create() cv.repository = [repo] cv.update(['repository']) cv.publish()
def test_parse_json(self): """Output generated with: hammer -u admin -p changeme --output json content-view info --id 1""" output = u"""{ "ID": 1, "Name": "Default Organization View", "Label": "Default_Organization_View", "Composite": false, "Description": null, "Content Host Count": 0, "Organization": "Default Organization", "Yum Repositories": { }, "Docker Repositories": { }, "OSTree Repositories": { }, "Puppet Modules": { }, "Lifecycle Environments": { "1": { "ID": 1, "Name": "Library" } }, "Versions": { "1": { "ID": 1, "Version": "1.0", "Published": "2016-07-05 17:35:33 UTC" } }, "Components": { }, "Activation Keys": { } }""" self.assertEqual( hammer.parse_json(output), { u'puppet-modules': {}, u'description': None, u'versions': { u'1': { u'version': u'1.0', u'id': u'1', u'published': u'2016-07-05 17:35:33 UTC' } }, u'composite': False, u'ostree-repositories': {}, u'label': u'Default_Organization_View', u'activation-keys': {}, u'docker-repositories': {}, u'components': {}, u'organization': u'Default Organization', u'yum-repositories': {}, u'lifecycle-environments': { u'1': { u'id': u'1', u'name': u'Library' } }, u'id': u'1', u'content-host-count': u'0', u'name': u'Default Organization View' } )
def test_parse_json_list(self): """Can parse a list in json""" self.assertEqual( hammer.parse_json('["item1", "item2"]'), ['item1', 'item2'] )
def test_parse_json_list(self): """Can parse a list in json""" self.assertEqual(hammer.parse_json('["item1", "item2"]'), ['item1', 'item2'])