def test_positive_run_job_effective_user_by_ip(self): """Run default job template as effective user on a host by ip :id: 0cd75cab-f699-47e6-94d3-4477d2a94bb7 :expectedresults: Verify the job was successfully run under the effective user identity on host """ # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='useradd {0}'".format(username), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(make_user_job[u'success'], u'1') except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': make_user_job[u'id'], 'host': self.client.hostname }))) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='touch /home/{0}/{1}'".format(username, filename), 'search-query': "name ~ {0}".format(self.client.hostname), 'effective-user': '******'.format(username), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }))) raise AssertionError(result) # check the file owner result = ssh.command('''stat -c '%U' /home/{0}/{1}'''.format( username, filename), hostname=self.client.ip_addr) # assert the file is owned by the effective user self.assertEqual(username, result.stdout[0])
def test_positive_run_reccuring_job(self, fixture_vmsetup, fixture_org): """Tests Ansible REX reccuring job runs successfully multiple times :id: 49b0d31d-58f9-47f1-aa5d-561a1dcb0d66 :Steps: 0. Create a VM and register to SAT and prepare for REX (ssh key) 1. Run recurring Ansible Command job for the host 2. Check the multiple job results at the host :expectedresults: multiple asserts along the code :caseautomation: automated :CaseLevel: System """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }) try: assert invocation_command['status'] == u'queued' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # Wait until the job runs pending_state = u'1' for _ in range(5): if pending_state != u'0': invocation_info = JobInvocation.info({ 'id': invocation_command[u'id']}) pending_state = invocation_info[u'pending'] sleep(30) rec_logic = RecurringLogic.info({ 'id': invocation_command['recurring-logic-id']}) assert rec_logic['state'] == u'finished' assert rec_logic['iteration'] == u'2'
def test_positive_run_job_effective_user_by_ip(self, fixture_vmsetup): """Run default job template as effective user on a host by ip :id: 0cd75cab-f699-47e6-94d3-4477d2a94bb7 :BZ: 1451675 :expectedresults: Verify the job was successfully run under the effective user identity on host :parametrized: yes """ client = fixture_vmsetup # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': f"command='useradd -m {username}'", 'search-query': f"name ~ {client.hostname}", }) result = JobInvocation.info({'id': make_user_job['id']}) try: assert result['success'] == '1' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': make_user_job['id'], 'host': client.hostname }))) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': f"command='touch /home/{username}/{filename}'", 'search-query': f"name ~ {client.hostname}", 'effective-user': f'{username}', }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['success'] == '1' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname }))) raise AssertionError(result) # check the file owner result = client.execute( f'''stat -c '%U' /home/{username}/{filename}''', ) # assert the file is owned by the effective user assert username == result.stdout.strip('\n')
def test_positive_run_recurring_job_with_max_iterations(self): """Run default job template multiple times with max iteration :id: 37fb7d77-dbb1-45ae-8bd7-c70be7f6d949 :expectedresults: Verify the job was run not more than the specified number of times. """ invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) if not bz_bug_is_open(1431190): JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }) try: self.assertEqual(invocation_command['status'], u'queued') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info({ 'id': invocation_command['recurring-logic-id']}) self.assertEqual(rec_logic['state'], u'finished') self.assertEqual(rec_logic['iteration'], u'2')
def test_positive_run_reccuring_job(self, fixture_vmsetup, fixture_org): """Tests Ansible REX reccuring job runs successfully multiple times :id: 49b0d31d-58f9-47f1-aa5d-561a1dcb0d66 :Steps: 0. Create a VM and register to SAT and prepare for REX (ssh key) 1. Run recurring Ansible Command job for the host 2. Check the multiple job results at the host :expectedresults: multiple asserts along the code :CaseAutomation: automated :CaseLevel: System :parametrized: yes """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) JobInvocation.get_output({ 'id': invocation_command['id'], 'host': self.client.hostname }) try: assert invocation_command['status'] == 'queued' except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': self.client.hostname }))) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info( {'id': invocation_command['recurring-logic-id']}) assert rec_logic['state'] == 'finished' assert rec_logic['iteration'] == '2'
def test_positive_run_job_effective_user_by_ip(self, fixture_vmsetup, fixture_org): """Run default job template as effective user on a host by ip :id: 0cd75cab-f699-47e6-94d3-4477d2a94bb7 :expectedresults: Verify the job was successfully run under the effective user identity on host """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='useradd -m {0}'".format(username), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: assert make_user_job[u'success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': make_user_job[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='touch /home/{0}/{1}'".format( username, filename), 'search-query': "name ~ {0}".format(self.client.hostname), 'effective-user': '******'.format(username), }) try: assert invocation_command['success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # check the file owner result = ssh.command( '''stat -c '%U' /home/{0}/{1}'''.format(username, filename), hostname=self.client.ip_addr ) # assert the file is owned by the effective user assert username == result.stdout[0]
def test_positive_run_job_effective_user(self): """Run default job template as effective user against a single host :id: ecd3f24f-26df-4a2c-9112-6af33b68b601 :expectedresults: Verify the job was successfully run under the effective user identity on host """ # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='useradd {0}'".format(username), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(make_user_job[u'success'], u'1') except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': make_user_job[u'id'], 'host': self.client.hostname }))) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='touch /home/{0}/{1}'".format(username, filename), 'search-query': "name ~ {0}".format(self.client.hostname), 'effective-user': '******'.format(username), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }))) raise AssertionError(result) # check the file owner result = ssh.command('''stat -c '%U' /home/{0}/{1}'''.format( username, filename), hostname=self.client.hostname) # assert the file is owned by the effective user self.assertEqual(username, result.stdout[0])
def test_positive_run_job_effective_user(self): """Run default job template as effective user against a single host :id: ecd3f24f-26df-4a2c-9112-6af33b68b601 :expectedresults: Verify the job was successfully run under the effective user identity on host """ # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='useradd {0}'".format(username), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(make_user_job[u'success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': make_user_job[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': "command='touch /home/{0}/{1}'".format( username, filename), 'search-query': "name ~ {0}".format(self.client.hostname), 'effective-user': '******'.format(username), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # check the file owner result = ssh.command( '''stat -c '%U' /home/{0}/{1}'''.format(username, filename), hostname=self.client.hostname ) # assert the file is owned by the effective user self.assertEqual(username, result.stdout[0])
def test_positive_run_recurring_job_with_max_iterations_by_ip( self, fixture_vmsetup, fixture_org): """Run default job template multiple times with max iteration by ip :id: 0a3d1627-95d9-42ab-9478-a908f2a7c509 :expectedresults: Verify the job was run not more than the specified number of times. :parametrized: yes """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) JobInvocation.get_output({ 'id': invocation_command['id'], 'host': self.client.hostname }) try: assert invocation_command['status'] == 'queued' except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': self.client.hostname }))) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info( {'id': invocation_command['recurring-logic-id']}) assert rec_logic['state'] == 'finished' assert rec_logic['iteration'] == '2'
def test_positive_run_custom_job_template(self): """Run a job template against a single host :id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7 :Setup: Create a working job template. :Steps: 1. Navigate to an individual host and click Run Job 2. Select the job and appropriate template 3. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: System """ jobs_template_name = gen_string('alpha') with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ u'name': client.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) make_job_template( session, name=jobs_template_name, template_type='input', template_content='<%= input("command") %>', provider_type='SSH', ) self.assertIsNotNone( self.jobtemplate.search(jobs_template_name)) self.jobtemplate.add_input( jobs_template_name, 'command', required=True) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run( job_category='Miscellaneous', job_template=jobs_template_name, options_list=[{'name': 'command', 'value': 'ls'}] ) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status, 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) )
def test_positive_run_default_job_template_by_ip(self, fixture_vmsetup, fixture_org): """Run default template on host connected by ip :id: 811c7747-bec6-4a2d-8e5c-b5045d3fbc0d :expectedresults: Verify the job was successfully ran against the host """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), }) try: assert invocation_command['success'] == u'1' except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }))) raise AssertionError(result)
def test_positive_run_custom_job_template(self): """Run custom job template against a single host :id: 71928f36-61b4-46e6-842c-a051cfd9a68e :expectedresults: Verify the job was successfully ran against the host """ template_name = gen_string('alpha', 7) make_job_template({ u'organizations': self.name, u'name': template_name, u'file': TEMPLATE_FILE }) invocation_command = make_job_invocation({ 'job-template': template_name, 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_default_job_template_by_ip(self): """Run default template on host connected by ip :id: 811c7747-bec6-4a2d-8e5c-b5045d3fbc0d :expectedresults: Verify the job was successfully ran against the host """ # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_default_job_template_multiple_hosts(self): """Run default job template against multiple hosts :id: 415c0156-be77-4676-918b-c0d4be810b0e :expectedresults: Verify the job was successfully ran against all hosts """ with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge, ) as client2: client2.install_katello_ca() client2.register_contenthost( self.org.label, lce='Library') add_remote_execution_ssh_key(client2.ip_addr) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0} or name ~ {1}".format( self.client.hostname, client2.hostname), }) # collect output messages from clients output_msgs = [] for vm in self.client, client2: output_msgs.append( 'host output from {0}: {1}'.format( vm.hostname, ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': vm.hostname}) ) ) ) self.assertEqual(invocation_command['success'], u'2', output_msgs)
def test_positive_run_custom_job_template_by_ip(self): """Run custom template on host connected by ip :id: 9740eb1d-59f5-42b2-b3ab-659ca0202c74 :expectedresults: Verify the job was successfully ran against the host """ # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) template_name = gen_string('alpha', 7) make_job_template({ u'organizations': self.org.name, u'name': template_name, u'file': TEMPLATE_FILE }) invocation_command = make_job_invocation({ 'job-template': template_name, 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_install_multiple_packages_with_a_job_by_ip(self): """Run job to install several packages on host by ip :id: 8b73033f-83c9-4024-83c3-5e442a79d320 :expectedresults: Verify the packages were successfully installed on host """ # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) packages = ["cow", "dog", "lion"] # Create a custom repo repo = entities.Repository( content_type='yum', product=entities.Product(organization=self.org).create(), url=FAKE_0_YUM_REPO, ).create() repo.sync() prod = repo.product.read() subs = entities.Subscription().search( query={'search': 'name={0}'.format(prod.name)} ) self.assertGreater( len(subs), 0, 'No subscriptions matching the product returned' ) ak = entities.ActivationKey( organization=self.org, content_view=self.org.default_content_view, environment=self.org.library ).create() ak.add_subscriptions(data={'subscriptions': [{'id': subs[0].id}]}) self.client.register_contenthost( org=self.org.label, activation_key=ak.name ) invocation_command = make_job_invocation({ 'job-template': 'Install Package - Katello SSH Default', 'inputs': 'package={0} {1} {2}'.format(*packages), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) result = ssh.command( "rpm -q {0}".format(" ".join(packages)), hostname=self.client.ip_addr ) self.assertEqual(result.return_code, 0)
def test_positive_run_custom_job_template_by_ip(self, fixture_vmsetup, module_org): """Run custom template on host connected by ip :id: 9740eb1d-59f5-42b2-b3ab-659ca0202c74 :expectedresults: Verify the job was successfully ran against the host :parametrized: yes """ self.org = module_org client = fixture_vmsetup template_file = 'template_file.txt' ssh.command(f'echo "echo Enforcing" > {template_file}') template_name = gen_string('alpha', 7) make_job_template( {'organizations': self.org.name, 'name': template_name, 'file': template_file} ) invocation_command = make_job_invocation( {'job-template': template_name, 'search-query': f"name ~ {client.hostname}"} ) try: assert invocation_command['success'] == '1' except AssertionError: result = 'host output: {}'.format( ' '.join( JobInvocation.get_output( {'id': invocation_command['id'], 'host': client.hostname} ) ) ) raise AssertionError(result)
def test_positive_run_default_job_template_multiple_hosts_by_ip( self, fixture_vmsetup, module_org): """Run default job template against multiple hosts by ip :id: 694a21d3-243b-4296-8bd0-4bad9663af15 :expectedresults: Verify the job was successfully ran against all hosts :parametrized: yes """ clients = fixture_vmsetup invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': f'name ~ {clients[0].hostname} or name ~ {clients[1].hostname}', }) # collect output messages from clients output_msgs = [] for vm in clients: output_msgs.append('host output from {}: {}'.format( vm.hostname, ' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': vm.hostname })), )) result = JobInvocation.info({'id': invocation_command['id']}) assert result['success'] == '2', output_msgs
def test_positive_run_recurring_job_with_max_iterations_by_ip( self, rex_contenthost): """Run default job template multiple times with max iteration by ip :id: 0a3d1627-95d9-42ab-9478-a908f2a7c509 :expectedresults: Verify the job was run not more than the specified number of times. :parametrized: yes """ client = rex_contenthost invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': f"name ~ {client.hostname}", 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['status'] == 'queued' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname }))) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info({'id': result['recurring-logic-id']}) assert rec_logic['state'] == 'finished' assert rec_logic['iteration'] == '2'
def test_positive_run_receptor_installer(self): """Run Receptor installer ("Configure Cloud Connector") :CaseComponent: RHCloud-CloudConnector :Assignee: lhellebr :id: 811c7747-bec6-1a2d-8e5c-b5045d3fbc0d :expectedresults: The job passes, installs Receptor that peers with c.r.c :BZ: 1818076 """ # Set Host parameter source_display_name to something random. # To avoid 'name has already been taken' error when run multiple times # on a machine with the same hostname. host_id = Host.info({'name': settings.server.hostname})['id'] Host.set_parameter({ 'host-id': host_id, 'name': 'source_display_name', 'value': gen_string('alpha') }) template_name = 'Configure Cloud Connector' invocation = make_job_invocation({ 'async': True, 'job-template': template_name, 'inputs': f'satellite_user="******",\ satellite_password="******"', 'search-query': f'name ~ {settings.server.hostname}', }) invocation_id = invocation['id'] wait_for( lambda: entities.JobInvocation(id=invocation_id).read(). status_label in ["succeeded", "failed"], timeout="1500s", ) assert entities.JobInvocation(id=invocation_id).read().status == 0 result = ' '.join( JobInvocation.get_output({ 'id': invocation_id, 'host': settings.server.hostname })) assert 'project-receptor.satellite_receptor_installer' in result assert 'Exit status: 0' in result # check that there is one receptor conf file and it's only readable # by the receptor user and root result = ssh.command( 'stat /etc/receptor/*/receptor.conf --format "%a:%U"') assert result.stdout[0] == '400:foreman-proxy' result = ssh.command('ls -l /etc/receptor/*/receptor.conf | wc -l') assert result.stdout[0] == '1'
def test_positive_run_default_job_template_by_ip(self): """Run a job template on a host connected by ip :id: 9a90aa9a-00b4-460e-b7e6-250360ee8e4d :Setup: Use pre-defined job template. :Steps: 1. Set remote_execution_connect_by_ip on host to true 2. Navigate to an individual host and click Run Job 3. Select the job and appropriate template 4. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: Integration """ with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge, ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ 'name': client.hostname, 'subnet-id': self.new_sub.id, }) # connect to host by ip Host.set_parameter({ 'host': client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run( job_category='Commands', job_template='Run Command - SSH Default', options_list=[{'name': 'command', 'value': 'ls'}] ) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] try: self.assertTrue(status) except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_custom_job_template(self): """Run a job template against a single host :id: 89b75feb-afff-44f2-a2bd-2ffe74b63ec7 :Setup: Create a working job template. :Steps: 1. Navigate to an individual host and click Run Job 2. Select the job and appropriate template 3. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: System """ jobs_template_name = gen_string('alpha') with VirtualMachine(distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ u'name': client.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) make_job_template( session, name=jobs_template_name, template_type='input', template_content='<%= input("command") %>', provider_type='SSH', ) self.assertIsNotNone( self.jobtemplate.search(jobs_template_name)) self.jobtemplate.add_input(jobs_template_name, 'command', required=True) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run(job_category='Miscellaneous', job_template=jobs_template_name, options_list=[{ 'name': 'command', 'value': 'ls' }]) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status, 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname }))))
def test_positive_run_recurring_job_with_max_iterations_by_ip(self, fixture_vmsetup, fixture_org): """Run default job template multiple times with max iteration by ip :id: 0a3d1627-95d9-42ab-9478-a908f2a7c509 :expectedresults: Verify the job was run not more than the specified number of times. """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) if not bz_bug_is_open(1431190): JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }) try: assert invocation_command['status'] == u'queued' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info({ 'id': invocation_command['recurring-logic-id']}) assert rec_logic['state'] == u'finished' assert rec_logic['iteration'] == u'2'
def test_positive_run_job_template_multiple_hosts(self): """Run a job template against multiple hosts :id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde :Setup: Create a working job template. :Steps: 1. Navigate to the hosts page and select at least two hosts 2. Click the "Select Action" 3. Select the job and appropriate template 4. Run the job :expectedresults: Verify the job was successfully ran against the hosts :CaseLevel: System """ with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge ) as client: with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge ) as client2: for vm in client, client2: vm.install_katello_ca() vm.register_contenthost( self.organization.label, lce='Library') self.assertTrue(vm.subscribed) add_remote_execution_ssh_key(vm.ip_addr) Host.update({ u'name': vm.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.update_host_bulkactions( [client.hostname, client2.hostname], action='Run Job', parameters_list=[{'command': 'ls'}], ) strategy, value = locators['job_invocation.status'] if self.job.wait_until_element( (strategy, value % 'succeeded'), 240) is not None: status = True else: status = False # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue(status, 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname }))))
def test_positive_run_job_template_multiple_hosts(self): """Run a job template against multiple hosts :id: 7f1981cb-afcc-49b7-a565-7fef9aa8ddde :Setup: Create a working job template. :Steps: 1. Navigate to the hosts page and select at least two hosts 2. Click the "Select Action" 3. Select the job and appropriate template 4. Run the job :expectedresults: Verify the job was successfully ran against the hosts :CaseLevel: System """ with VirtualMachine(distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge) as client: with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge) as client2: for vm in client, client2: vm.install_katello_ca() vm.register_contenthost(self.organization.label, lce='Library') self.assertTrue(vm.subscribed) add_remote_execution_ssh_key(vm.ip_addr) Host.update({ u'name': vm.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.update_host_bulkactions( [client.hostname, client2.hostname], action='Run Job', parameters_list=[{ 'command': 'ls' }], ) strategy, value = locators['job_invocation.status'] if self.job.wait_until_element( (strategy, value % 'succeeded'), 240) is not None: status = True else: status = False # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status, 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname }))))
def test_positive_run_default_job_template_multiple_hosts_by_ip( self, fixture_vmsetup, fixture_org ): """Run default job template against multiple hosts by ip :id: 694a21d3-243b-4296-8bd0-4bad9663af15 :expectedresults: Verify the job was successfully ran against all hosts :parametrized: yes """ self.org = fixture_org self.client = fixture_vmsetup Host.set_parameter( { 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', } ) with VirtualMachine(distro=DISTRO_RHEL7) as client2: client2.install_katello_ca() client2.register_contenthost(self.org.label, lce='Library') add_remote_execution_ssh_key(client2.ip_addr) Host.set_parameter( { 'host': client2.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', } ) invocation_command = make_job_invocation( { 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {} or name ~ {}".format( self.client.hostname, client2.hostname ), } ) # collect output messages from clients output_msgs = [] for vm in self.client, client2: output_msgs.append( 'host output from {}: {}'.format( vm.hostname, ' '.join( JobInvocation.get_output( {'id': invocation_command['id'], 'host': vm.hostname} ) ), ) ) assert invocation_command['success'] == '2', output_msgs
def test_positive_install_multiple_packages_with_a_job_by_ip( self, fixture_vmsetup, module_org): """Run job to install several packages on host by ip :id: 8b73033f-83c9-4024-83c3-5e442a79d320 :expectedresults: Verify the packages were successfully installed on host :parametrized: yes """ self.org = module_org client = fixture_vmsetup packages = ["cow", "dog", "lion"] # Create a custom repo repo = entities.Repository( content_type='yum', product=entities.Product(organization=self.org).create(), url=settings.repos.yum_0.url, ).create() repo.sync() prod = repo.product.read() subs = entities.Subscription(organization=self.org).search( query={'search': f'name={prod.name}'}) assert len(subs) > 0, 'No subscriptions matching the product returned' ak = entities.ActivationKey( organization=self.org, content_view=self.org.default_content_view, environment=self.org.library, ).create() ak.add_subscriptions(data={'subscriptions': [{'id': subs[0].id}]}) client.register_contenthost(org=self.org.label, activation_key=ak.name) invocation_command = make_job_invocation({ 'job-template': 'Install Package - Katello SSH Default', 'inputs': 'package={} {} {}'.format(*packages), 'search-query': f'name ~ {client.hostname}', }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['success'] == '1' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname }))) raise AssertionError(result) result = client.run(f'rpm -q {" ".join(packages)}') assert result.status == 0
def test_positive_run_scheduled_job_template_by_ip(self, fixture_vmsetup, fixture_org): """Schedule a job to be ran against a host :id: 0407e3de-ef59-4706-ae0d-b81172b81e5c :expectedresults: Verify the job was successfully ran after the designated time :parametrized: yes """ self.org = fixture_org self.client = fixture_vmsetup system_current_time = ssh.command( 'date --utc +"%b %d %Y %I:%M%p"').stdout[0] current_time_object = datetime.strptime(system_current_time, '%b %d %Y %I:%M%p') plan_time = (current_time_object + timedelta(seconds=30)).strftime("%Y-%m-%d %H:%M") Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'start-at': plan_time, 'search-query': "name ~ {0}".format(self.client.hostname), }) # Wait until the job runs pending_state = '1' while pending_state != '0': invocation_info = JobInvocation.info( {'id': invocation_command['id']}) pending_state = invocation_info['pending'] sleep(30) invocation_info = JobInvocation.info({'id': invocation_command['id']}) try: assert invocation_info['success'] == '1' except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': self.client.hostname }))) raise AssertionError(result)
def test_positive_use_alternate_directory(self, fixture_vmsetup, module_org, default_sat): """Use alternate working directory on client to execute rex jobs :id: a0181f18-d3dc-4bd9-a2a6-430c2a49809e :expectedresults: Verify the job was successfully ran against the host :customerscenario: true :parametrized: yes """ client = fixture_vmsetup testdir = gen_string('alpha') result = client.run(f'mkdir /{testdir}') assert result.status == 0 result = client.run(f'chcon --reference=/var /{testdir}') assert result.status == 0 result = default_sat.execute( f"sed -i r's/^:remote_working_dir:.*/:remote_working_dir: \\/{testdir}/' \ /etc/foreman-proxy/settings.d/remote_execution_ssh.yml", ) assert result.status == 0 result = default_sat.execute('systemctl restart foreman-proxy') assert result.status == 0 command = f'echo {gen_string("alpha")}' invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': f'command={command}', 'search-query': f"name ~ {client.hostname}", }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['success'] == '1' except AssertionError: output = ' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname })) result = f'host output: {output}' raise AssertionError(result) task = Task.list_tasks({"search": command})[0] search = Task.list_tasks({"search": f'id={task["id"]}'}) assert search[0]["action"] == task["action"]
def test_positive_run_default_job_template(self): """Run a job template against a single host :id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217 :Setup: Use pre-defined job template. :Steps: 1. Navigate to an individual host and click Run Job 2. Select the job and appropriate template 3. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: Integration """ with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ u'name': client.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run( job_category='Commands', job_template='Run Command - SSH Default', options_list=[{'name': 'command', 'value': 'ls'}] ) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status, 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) )
def test_positive_run_receptor_installer(self): """Run Receptor installer ("Configure Cloud Connector") :CaseComponent: RHCloud-CloudConnector :id: 811c7747-bec6-1a2d-8e5c-b5045d3fbc0d :expectedresults: The job passes, installs Receptor that peers with c.r.c :BZ: 1818076 """ template_name = 'Configure Cloud Connector' invocation = make_job_invocation({ 'async': True, 'job-template': template_name, 'inputs': 'satellite_user="******",satellite_password="******"'.format( settings.server.admin_username, settings.server.admin_password), 'search-query': "name ~ {0}".format(settings.server.hostname), }) invocation_id = invocation['id'] wait_for( lambda: entities.JobInvocation(id=invocation_id).read(). status_label in ["succeeded", "failed"], timeout="1500s", ) assert entities.JobInvocation(id=invocation_id).read().status == 0 result = ' '.join( JobInvocation.get_output({ 'id': invocation_id, 'host': settings.server.hostname })) assert 'project-receptor.satellite_receptor_installer' in result assert 'Exit status: 0' in result # check that there is one receptor conf file and it's only readable # by the receptor user and root result = ssh.command( 'stat /etc/receptor/*/receptor.conf --format "%a:%U"') assert result.stdout[0] == '400:foreman-proxy' result = ssh.command('ls -l /etc/receptor/*/receptor.conf | wc -l') assert result.stdout[0] == '1'
def test_positive_run_concurrent_jobs(self, fixture_vmsetup, module_org): """Tests Ansible REX concurent jobs without batch trigger :id: ad0f108c-03f2-49c7-8732-b1056570567b :Steps: 0. Create 2 hosts, disable foreman_tasks_proxy_batch_trigger 1. Run Ansible Command job with concurrency-setting :expectedresults: multiple asserts along the code :CaseAutomation: Automated :customerscenario: true :CaseLevel: System :BZ: 1817320 :parametrized: yes """ param_name = 'foreman_tasks_proxy_batch_trigger' GlobalParameter().set({'name': param_name, 'value': 'false'}) clients = fixture_vmsetup output_msgs = [] invocation_command = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': 'command="ls"', 'search-query': f'name ~ {clients[0].hostname} or name ~ {clients[1].hostname}', 'concurrency-level': 2, }) for vm in clients: output_msgs.append('host output from {}: {}'.format( vm.hostname, ' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': vm.hostname })), )) result = JobInvocation.info({'id': invocation_command['id']}) assert result['success'] == '2', output_msgs GlobalParameter().delete({'name': param_name}) assert len(GlobalParameter().list({'search': param_name})) == 0
def test_positive_run_default_job_template_by_ip(self, fixture_vmsetup, fixture_org): """Run default template on host connected by ip and list task :id: 811c7747-bec6-4a2d-8e5c-b5045d3fbc0d :expectedresults: Verify the job was successfully ran against the host and task can be listed by name and ID :BZ: 1647582 :parametrized: yes """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host via ip Host.set_parameter( { 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', } ) command = "echo {}".format(gen_string('alpha')) invocation_command = make_job_invocation( { 'job-template': 'Run Command - SSH Default', 'inputs': f'command={command}', 'search-query': f"name ~ {self.client.hostname}", } ) try: assert invocation_command['success'] == '1' except AssertionError: result = 'host output: {}'.format( ' '.join( JobInvocation.get_output( {'id': invocation_command['id'], 'host': self.client.hostname} ) ) ) raise AssertionError(result) task = Task.list_tasks({"search": command})[0] search = Task.list_tasks({"search": 'id={}'.format(task["id"])}) assert search[0]["action"] == task["action"]
def test_positive_run_scheduled_job_template_by_ip(self, fixture_vmsetup, fixture_org): """Schedule a job to be ran against a host :id: 0407e3de-ef59-4706-ae0d-b81172b81e5c :expectedresults: Verify the job was successfully ran after the designated time """ self.org = fixture_org self.client = fixture_vmsetup system_current_time = ssh.command('date --utc +"%b %d %Y %I:%M%p"').stdout[0] current_time_object = datetime.strptime( system_current_time, '%b %d %Y %I:%M%p') plan_time = (current_time_object + timedelta(seconds=30)).strftime( "%Y-%m-%d %H:%M") Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'start-at': plan_time, 'search-query': "name ~ {0}".format(self.client.hostname), }) # Wait until the job runs pending_state = u'1' while pending_state != u'0': invocation_info = JobInvocation.info({ 'id': invocation_command[u'id']}) pending_state = invocation_info[u'pending'] sleep(30) invocation_info = JobInvocation.info({ 'id': invocation_command[u'id']}) try: assert invocation_info['success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_default_job_template_multiple_hosts_by_ip(self): """Run default job template against multiple hosts by ip :id: 694a21d3-243b-4296-8bd0-4bad9663af15 :expectedresults: Verify the job was successfully ran against all hosts """ Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge, ) as client2: client2.install_katello_ca() client2.register_contenthost( self.org['label'], lce='Library') add_remote_execution_ssh_key(client2.ip_addr) Host.set_parameter({ 'host': client2.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0} or name ~ {1}".format( self.client.hostname, client2.hostname), }) # collect output messages from clients output_msgs = [] for vm in self.client, client2: output_msgs.append('host output from {0}: {1}'.format( vm.hostname, ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': vm.hostname}) ) ) ) self.assertEqual(invocation_command['success'], u'2', output_msgs)
def test_positive_run_default_job_template(self): """Run a job template against a single host :id: 7f0cdd1a-c87c-4324-ae9c-dbc30abad217 :Setup: Use pre-defined job template. :Steps: 1. Navigate to an individual host and click Run Job 2. Select the job and appropriate template 3. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: Integration """ with VirtualMachine(distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ u'name': client.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run(job_category='Commands', job_template='Run Command - SSH Default', options_list=[{ 'name': 'command', 'value': 'ls' }]) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status, 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname }))))
def test_positive_run_reccuring_job(self, rex_contenthost): """Tests Ansible REX reccuring job runs successfully multiple times :id: 49b0d31d-58f9-47f1-aa5d-561a1dcb0d66 :Steps: 0. Create a VM and register to SAT and prepare for REX (ssh key) 1. Run recurring Ansible Command job for the host 2. Check the multiple job results at the host :expectedresults: multiple asserts along the code :CaseAutomation: Automated :CaseLevel: System :parametrized: yes """ client = rex_contenthost invocation_command = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': 'command="ls"', 'search-query': f"name ~ {client.hostname}", 'cron-line': '* * * * *', # every minute 'max-iteration': 2, # just two runs }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['status'] == 'queued' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname }))) raise AssertionError(result) sleep(150) rec_logic = RecurringLogic.info({'id': result['recurring-logic-id']}) assert rec_logic['state'] == 'finished' assert rec_logic['iteration'] == '2'
def test_positive_install_multiple_packages_with_a_job_by_ip(self): """Run job to install several packages on host by ip :id: 8b73033f-83c9-4024-83c3-5e442a79d320 :expectedresults: Verify the packages were successfully installed on host """ # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) packages = ["cow", "dog", "lion"] # Create a custom repo setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': self.org['id'], u'content-view-id': self.content_view['id'], u'lifecycle-environment-id': self.env['id'], u'activationkey-id': self.activation_key['id'], }) invocation_command = make_job_invocation({ 'job-template': 'Install Package - Katello SSH Default', 'inputs': 'package={0} {1} {2}'.format(*packages), 'search-query': "name ~ {0}".format(self.client.hostname), }) self.assertEqual( invocation_command['success'], u'1', 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) ) result = ssh.command( "rpm -q {0}".format(" ".join(packages)), hostname=self.client.ip_addr ) self.assertEqual(result.return_code, 0)
def test_positive_run_custom_job_template_by_ip(self, rex_contenthost, module_org, default_sat): """Run custom template on host connected by ip :id: 9740eb1d-59f5-42b2-b3ab-659ca0202c74 :expectedresults: Verify the job was successfully ran against the host :bz: 1872688, 1811166 :customerscenario: true :CaseImportance: Critical :parametrized: yes """ self.org = module_org client = rex_contenthost template_file = 'template_file.txt' default_sat.execute(f'echo "echo Enforcing" > {template_file}') template_name = gen_string('alpha', 7) make_job_template({ 'organizations': self.org.name, 'name': template_name, 'file': template_file }) invocation_command = make_job_invocation({ 'job-template': template_name, 'search-query': f'name ~ {client.hostname}' }) result = JobInvocation.info({'id': invocation_command['id']}) try: assert result['success'] == '1' except AssertionError: result = 'host output: {}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command['id'], 'host': client.hostname }))) raise AssertionError(result)
def test_positive_run_scheduled_job_template(self): """Schedule a job to be ran against a host :id: 1953517b-6908-40aa-858b-747629d2f374 :expectedresults: Verify the job was successfully ran after the designated time """ system_current_time = ssh.command('date +"%b %d %Y %I:%M%p"').stdout[0] current_time_object = datetime.strptime(system_current_time, '%b %d %Y %I:%M%p') plan_time = (current_time_object + timedelta(seconds=30)).strftime("%Y-%m-%d %H:%M") invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'start-at': plan_time, 'search-query': "name ~ {0}".format(self.client.hostname), }) # Wait until the job runs pending_state = u'1' while pending_state != u'0': invocation_info = JobInvocation.info( {'id': invocation_command[u'id']}) pending_state = invocation_info[u'pending'] sleep(30) invocation_info = JobInvocation.info({'id': invocation_command[u'id']}) try: self.assertEqual(invocation_info['success'], u'1') except AssertionError: result = 'host output: {0}'.format(' '.join( JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname }))) raise AssertionError(result)
def test_positive_run_default_job_template(self): """Run default job template against a single host :id: f4470ed4-f971-4a3c-a2f1-150d45755e48 :expectedresults: Verify the job was successfully ran against the host """ invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'search-query': "name ~ {0}".format(self.client.hostname), }) try: self.assertEqual(invocation_command['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_scheduled_job_template(self): """Schedule a job to be ran against a host :id: 1953517b-6908-40aa-858b-747629d2f374 :expectedresults: Verify the job was successfully ran after the designated time """ system_current_time = ssh.command('date +"%b %d %Y %I:%M%p"').stdout[0] current_time_object = datetime.strptime( system_current_time, '%b %d %Y %I:%M%p') plan_time = (current_time_object + timedelta(seconds=30)).strftime( "%Y-%m-%d %H:%M") invocation_command = make_job_invocation({ 'job-template': 'Run Command - SSH Default', 'inputs': 'command="ls"', 'start-at': plan_time, 'search-query': "name ~ {0}".format(self.client.hostname), }) # Wait until the job runs pending_state = u'1' while pending_state != u'0': invocation_info = JobInvocation.info({ 'id': invocation_command[u'id']}) pending_state = invocation_info[u'pending'] sleep(30) invocation_info = JobInvocation.info({ 'id': invocation_command[u'id']}) try: self.assertEqual(invocation_info['success'], u'1') except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result)
def test_positive_install_multiple_packages_with_a_job(self): """Run job to install several packages on host :id: 1cf2709e-e6cd-46c9-a7b7-c2e542c0e943 :expectedresults: Verify the packages were successfully installed on host """ packages = ["cow", "dog", "lion"] # Create a custom repo setup_org_for_a_custom_repo({ u'url': FAKE_0_YUM_REPO, u'organization-id': self.org['id'], u'content-view-id': self.content_view['id'], u'lifecycle-environment-id': self.env['id'], u'activationkey-id': self.activation_key['id'], }) invocation_command = make_job_invocation({ 'job-template': 'Install Package - Katello SSH Default', 'inputs': 'package={0} {1} {2}'.format(*packages), 'search-query': "name ~ {0}".format(self.client.hostname), }) self.assertEqual( invocation_command['success'], u'1', 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) ) result = ssh.command( "rpm -q {0}".format(" ".join(packages)), hostname=self.client.hostname ) self.assertEqual(result.return_code, 0)
def test_positive_run_scheduled_job_template(self): """Schedule a job to be ran against a host :id: 35c8b68e-1ac5-4c33-ad62-a939b87f76fb :Setup: Use pre-defined job template. :Steps: 1. Navigate to an individual host and click Run Job 2. Select the job and appropriate template 3. Select "Schedule Future Job" 4. Enter a desired time for the job to run 5. Click submit :expectedresults: 1. Verify the job was not immediately ran 2. Verify the job was successfully ran after the designated time :CaseLevel: System """ with VirtualMachine( distro=DISTRO_RHEL7, bridge=settings.vlan_networking.bridge ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ u'name': client.hostname, u'subnet-id': self.new_sub['id'], }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.click(self.hosts.search(client.hostname)) plan_time = ( self.get_client_datetime() + timedelta(seconds=90) ).strftime("%Y-%m-%d %H:%M") status = self.job.run( job_category='Commands', job_template='Run Command - SSH Default', options_list=[{'name': 'command', 'value': 'ls'}], schedule='future', schedule_options=[ {'name': 'start_at', 'value': plan_time}], result='queued' ) self.assertTrue(status) strategy, value = locators['job_invocation.status'] self.job.wait_until_element_is_not_visible( (strategy, value % 'queued'), 95) if self.job.wait_until_element( (strategy, value % 'succeeded'), 180) is not None: status2 = True else: status2 = False # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] self.assertTrue( status2, 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) )
def test_positive_run_effective_user_job(self, fixture_vmsetup, fixture_org): """Tests Ansible REX job having effective user runs successfully :id: a5fa20d8-c2bd-4bbf-a6dc-bf307b59dd8c :Steps: 0. Create a VM and register to SAT and prepare for REX (ssh key) 1. Run Ansible Command job for the host to create a user 2. Run Ansible Command job using effective user 3. Check the job result at the host is done under that user :expectedresults: multiple asserts along the code :caseautomation: automated :CaseLevel: System """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host via ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) # create a user on client via remote job username = gen_string('alpha') filename = gen_string('alpha') make_user_job = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': "command='useradd -m {0}'".format(username), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: assert make_user_job[u'success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': make_user_job[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # create a file as new user invocation_command = make_job_invocation({ 'job-template': 'Run Command - Ansible Default', 'inputs': "command='touch /home/{0}/{1}'".format( username, filename), 'search-query': "name ~ {0}".format(self.client.hostname), 'effective-user': '******'.format(username), }) try: assert invocation_command['success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) # check the file owner result = ssh.command( '''stat -c '%U' /home/{0}/{1}'''.format(username, filename), hostname=self.client.ip_addr ) # assert the file is owned by the effective user assert username == result.stdout[0], "file ownership mismatch"
def test_positive_run_packages_and_services_job(self, fixture_vmsetup, fixture_org): """Tests Ansible REX job can install packages and start services :id: 47ed82fb-77ca-43d6-a52e-f62bae5d3a42 :Steps: 0. Create a VM and register to SAT and prepare for REX (ssh key) 1. Run Ansible Package job for the host to install a package 2. Check the package is present at the host 3. Run Ansible Service job for the host to start a service 4. Check the service is started on the host :expectedresults: multiple asserts along the code :caseautomation: automated :CaseLevel: System """ self.org = fixture_org self.client = fixture_vmsetup # set connecting to host by ip Host.set_parameter({ 'host': self.client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) packages = ["cow"] # Create a custom repo repo = entities.Repository( content_type='yum', product=entities.Product(organization=self.org).create(), url=FAKE_0_YUM_REPO, ).create() repo.sync() prod = repo.product.read() subs = entities.Subscription().search( query={'search': 'name={0}'.format(prod.name)} ) assert len(subs) > 0, 'No subscriptions matching the product returned' ak = entities.ActivationKey( organization=self.org, content_view=self.org.default_content_view, environment=self.org.library ).create() ak.add_subscriptions(data={'subscriptions': [{'id': subs[0].id}]}) self.client.register_contenthost( org=self.org.label, activation_key=ak.name ) # install package invocation_command = make_job_invocation({ 'job-template': 'Package Action - Ansible Default', 'inputs': 'state=latest, name={}'.format(*packages), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: assert invocation_command['success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) result = ssh.command( "rpm -q {0}".format(*packages), hostname=self.client.ip_addr ) assert result.return_code == 0 # start a service service = "postfix" ssh.command( "sed -i 's/^inet_protocols.*/inet_protocols = ipv4/' /etc/postfix/main.cf", hostname=self.client.ip_addr ) invocation_command = make_job_invocation({ 'job-template': 'Service Action - Ansible Default', 'inputs': 'state=started, name={}'.format(service), 'search-query': "name ~ {0}".format(self.client.hostname), }) try: assert invocation_command['success'] == u'1' except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_command[u'id'], 'host': self.client.hostname}) ) ) raise AssertionError(result) result = ssh.command( "systemctl status {0}".format(service), hostname=self.client.ip_addr ) assert result.return_code == 0
def test_positive_run_custom_job_template_by_ip(self): """Run a job template on a host connected by ip :id: e283ae09-8b14-4ce1-9a76-c1bbd511d58c :Setup: Create a working job template. :Steps: 1. Set remote_execution_connect_by_ip on host to true 2. Navigate to an individual host and click Run Job 3. Select the job and appropriate template 4. Run the job :expectedresults: Verify the job was successfully ran against the host :CaseLevel: System """ jobs_template_name = gen_string('alpha') with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge, ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ 'name': client.hostname, 'subnet-id': self.new_sub.id, }) # connect to host by ip Host.set_parameter({ 'host': client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) with Session(self) as session: set_context(session, org=self.organization.name) make_job_template( session, name=jobs_template_name, template_type='input', template_content='<%= input("command") %>', provider_type='SSH', ) self.assertIsNotNone( self.jobtemplate.search(jobs_template_name)) self.jobtemplate.add_input( jobs_template_name, 'command', required=True) self.hosts.click(self.hosts.search(client.hostname)) status = self.job.run( job_category='Miscellaneous', job_template=jobs_template_name, options_list=[{'name': 'command', 'value': 'ls'}] ) # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] try: self.assertTrue(status) except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_job_template_multiple_hosts_by_ip(self): """Run a job template against multiple hosts by ip :id: c4439ec0-bb80-47f6-bc31-fa7193bfbeeb :Setup: Create a working job template. :Steps: 1. Set remote_execution_connect_by_ip on hosts to true 2. Navigate to the hosts page and select at least two hosts 3. Click the "Select Action" 4. Select the job and appropriate template 5. Run the job :expectedresults: Verify the job was successfully ran against the hosts :CaseLevel: System """ prov_server = settings.compute_resources.libvirt_hostname with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=prov_server, bridge=settings.vlan_networking.bridge, ) as client: with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=prov_server, bridge=settings.vlan_networking.bridge, ) as client2: for vm in client, client2: vm.install_katello_ca() vm.register_contenthost( self.organization.label, lce='Library') self.assertTrue(vm.subscribed) add_remote_execution_ssh_key(vm.ip_addr) Host.update({ 'name': vm.hostname, 'subnet-id': self.new_sub.id, }) # connect to host by ip Host.set_parameter({ 'host': vm.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.update_host_bulkactions( [client.hostname, client2.hostname], action='Schedule Remote Job', parameters_list=[{'command': 'ls'}], ) strategy, value = locators['job_invocation.status'] if self.job.wait_until_element( (strategy, value % 'succeeded'), 240) is not None: status = True else: status = False # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] try: self.assertTrue(status) except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) raise AssertionError(result)
def test_positive_run_scheduled_job_template_by_ip(self): """Schedule a job to be ran against a host by ip :id: 4387bed9-969d-45fb-80c2-b0905bb7f1bd :Setup: Use pre-defined job template. :Steps: 1. Set remote_execution_connect_by_ip on host to true 2. Navigate to an individual host and click Run Job 3. Select the job and appropriate template 4. Select "Schedule Future Job" 5. Enter a desired time for the job to run 6. Click submit :expectedresults: 1. Verify the job was not immediately ran 2. Verify the job was successfully ran after the designated time :CaseLevel: System """ with VirtualMachine( distro=DISTRO_RHEL7, provisioning_server=settings.compute_resources.libvirt_hostname, bridge=settings.vlan_networking.bridge, ) as client: client.install_katello_ca() client.register_contenthost(self.organization.label, lce='Library') self.assertTrue(client.subscribed) add_remote_execution_ssh_key(client.ip_addr) Host.update({ 'name': client.hostname, 'subnet-id': self.new_sub.id, }) # connect to host by ip Host.set_parameter({ 'host': client.hostname, 'name': 'remote_execution_connect_by_ip', 'value': 'True', }) with Session(self) as session: set_context(session, org=self.organization.name) self.hosts.click(self.hosts.search(client.hostname)) plan_time = ( self.get_client_datetime() + timedelta(seconds=180) ).strftime("%Y-%m-%d %H:%M") status = self.job.run( job_category='Commands', job_template='Run Command - SSH Default', options_list=[{'name': 'command', 'value': 'ls'}], schedule='future', schedule_options=[ {'name': 'start_at', 'value': plan_time}], result='queued to start executing in 1 minute' ) self.assertTrue(status) strategy, value = locators['job_invocation.status'] self.job.wait_until_element_is_not_visible( (strategy, value % 'queued'), 95) if self.job.wait_until_element( (strategy, value % 'succeeded'), 180) is not None: status2 = True else: status2 = False # get job invocation id from the current url invocation_id = self.browser.current_url.rsplit('/', 1)[-1] try: self.assertTrue(status2) except AssertionError: result = 'host output: {0}'.format( ' '.join(JobInvocation.get_output({ 'id': invocation_id, 'host': client.hostname}) ) ) raise AssertionError(result)