Exemplo n.º 1
0
    def test_watchdog_extend_by_fqdn(self):
        with session.begin():
            lc = data_setup.create_labcontroller()
            system = data_setup.create_system(lab_controller=lc)
            recipe = data_setup.create_recipe()
            data_setup.create_job_for_recipes([recipe])
            data_setup.mark_recipe_running(recipe, system=system)

        run_client(['bkr', 'watchdog-extend', '--by=600', system.fqdn])

        with session.begin():
            session.expire_all()
            assert_datetime_within(recipe.watchdog.kill_time,
                                   tolerance=datetime.timedelta(seconds=10),
                                   reference=datetime.datetime.utcnow() +
                                   datetime.timedelta(seconds=600))
        # nonexistent fqdn
        try:
            run_client(
                ['bkr', 'watchdog-extend', 'ireallydontexistblah.test.fqdn'])
            self.fail('Must raise')
        except ClientError as e:
            self.assertIn(
                'Cannot find any recipe running on ireallydontexistblah.test.fqdn',
                e.stderr_output)
Exemplo n.º 2
0
 def test_change_status(self):
     orig_date_modified = self.system.date_modified
     b = self.browser
     login(b)
     self.go_to_system_view(tab='Scheduler Settings')
     tab = b.find_element_by_id('scheduler-settings')
     BootstrapSelect(tab.find_element_by_name('status'))\
         .select_by_visible_text('Broken')
     tab.find_element_by_xpath('.//button[text()="Save Changes"]').click()
     b.find_element_by_xpath('//span[@class="label label-warning"'
             ' and text()="Out of service"]')
     with session.begin():
         session.refresh(self.system)
         self.assertEqual(self.system.status, SystemStatus.broken)
         self.assertEqual(len(self.system.status_durations), 2)
         self.assertEqual(self.system.status_durations[0].status,
                 SystemStatus.broken)
         assertions.assert_datetime_within(
                 self.system.status_durations[0].start_time,
                 tolerance=datetime.timedelta(seconds=60),
                 reference=datetime.datetime.utcnow())
         self.assert_(self.system.status_durations[0].finish_time is None)
         self.assert_(self.system.status_durations[1].finish_time is not None)
         assertions.assert_durations_not_overlapping(
                 self.system.status_durations)
         self.assert_(self.system.date_modified > orig_date_modified)
Exemplo n.º 3
0
 def test_change_status(self):
     orig_date_modified = self.system.date_modified
     b = self.browser
     login(b)
     self.go_to_system_view(tab='Scheduler Settings')
     tab = b.find_element_by_id('scheduler-settings')
     BootstrapSelect(tab.find_element_by_name('status'))\
         .select_by_visible_text('Broken')
     tab.find_element_by_xpath('.//button[text()="Save Changes"]').click()
     b.find_element_by_xpath('//span[@class="label label-warning"'
                             ' and text()="Out of service"]')
     with session.begin():
         session.refresh(self.system)
         self.assertEqual(self.system.status, SystemStatus.broken)
         self.assertEqual(len(self.system.status_durations), 2)
         self.assertEqual(self.system.status_durations[0].status,
                          SystemStatus.broken)
         assertions.assert_datetime_within(
             self.system.status_durations[0].start_time,
             tolerance=datetime.timedelta(seconds=60),
             reference=datetime.datetime.utcnow())
         self.assert_(self.system.status_durations[0].finish_time is None)
         self.assert_(
             self.system.status_durations[1].finish_time is not None)
         assertions.assert_durations_not_overlapping(
             self.system.status_durations)
         self.assert_(self.system.date_modified > orig_date_modified)
Exemplo n.º 4
0
 def test_watchdog_extend_by_plain_task_id(self):
     run_client(['bkr','watchdog-extend', '--by=600', str(self.recipe.tasks[0].id)])
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
Exemplo n.º 5
0
 def test_mark_note_as_deleted(self):
     # Notes never get actually deleted, they just get marked as "deleted"
     # which hides them by default in the UI. "Obsoleted" would be a better
     # word but "deleted" is what we have.
     with session.begin():
         note_text = u'some obsolete info'
         self.system.notes.append(Note(text=note_text, user=self.owner))
         session.flush()
         note_id = self.system.notes[0].id
     s = requests.Session()
     requests_login(s, user=self.owner.user_name, password=u'owner')
     response = patch_json(get_server_base() + 'systems/%s/notes/%s' %
                           (self.system.fqdn, note_id),
                           session=s,
                           data={'deleted': 'now'})
     response.raise_for_status()
     self.assertEquals(response.json()['id'], note_id)
     assert_datetime_within(datetime.datetime.strptime(
         response.json()['deleted'], '%Y-%m-%d %H:%M:%S'),
                            reference=datetime.datetime.utcnow(),
                            tolerance=datetime.timedelta(seconds=10))
     with session.begin():
         session.refresh(self.system.notes[0])
         assert_datetime_within(self.system.notes[0].deleted,
                                reference=datetime.datetime.utcnow(),
                                tolerance=datetime.timedelta(seconds=10))
Exemplo n.º 6
0
 def test_release_system(self):
     with session.begin():
         system = data_setup.create_system(
                 owner=User.by_user_name(data_setup.ADMIN_USER),
                 status=u'Manual', shared=True)
         user = data_setup.create_user(password=u'password')
         system.reserve_manually(service=u'testdata', user=user)
     server = self.get_server()
     server.auth.login_password(user.user_name, 'password')
     server.systems.release(system.fqdn)
     with session.begin():
         session.refresh(system)
         session.refresh(system.reservations[0])
         self.assert_(system.user is None)
         self.assertEquals(system.reservations[0].user, user)
         assert_datetime_within(system.reservations[0].finish_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow())
         assert_durations_not_overlapping(system.reservations)
         released_activity = system.activity[0]
         self.assertEqual(released_activity.action, 'Returned')
         self.assertEqual(released_activity.field_name, 'User')
         self.assertEqual(released_activity.user, user)
         self.assertEqual(released_activity.old_value, user.user_name)
         self.assertEqual(released_activity.new_value, '')
         self.assertEqual(released_activity.service, 'XMLRPC')
Exemplo n.º 7
0
 def test_xmlrpc_extend_watchdog(self):
     s = xmlrpclib.ServerProxy(self.get_proxy_url())
     result_id = s.extend_watchdog(self.recipe.tasks[0].id, 600)
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
Exemplo n.º 8
0
 def test_watchdog_extend_by_recipe_task(self):
     run_client(
         ['bkr', 'watchdog-extend', '--by=600', self.recipe.tasks[0].t_id])
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                                tolerance=datetime.timedelta(seconds=10),
                                reference=datetime.datetime.utcnow() +
                                datetime.timedelta(seconds=600))
Exemplo n.º 9
0
 def test_xmlrpc_extend_watchdog(self):
     s = xmlrpclib.ServerProxy(self.get_proxy_url())
     result_id = s.extend_watchdog(self.recipe.tasks[0].id, 600)
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                                tolerance=datetime.timedelta(seconds=10),
                                reference=datetime.datetime.utcnow() +
                                datetime.timedelta(seconds=600))
Exemplo n.º 10
0
 def test_POST_watchdog(self):
     watchdog_url = '%srecipes/%s/watchdog' % (self.get_proxy_url(),
             self.recipe.id)
     response = requests.post(watchdog_url, data=dict(seconds=600))
     self.assertEquals(response.status_code, 204)
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
Exemplo n.º 11
0
 def test_POST_watchdog(self):
     watchdog_url = '%srecipes/%s/watchdog' % (self.get_proxy_url(),
                                               self.recipe.id)
     response = requests.post(watchdog_url, data=dict(seconds=600))
     self.assertEquals(response.status_code, 204)
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                                tolerance=datetime.timedelta(seconds=10),
                                reference=datetime.datetime.utcnow() +
                                datetime.timedelta(seconds=600))
Exemplo n.º 12
0
 def test_initial_watchdog_set_correctly(self):
     # When a task is started the watchdog is implicitly extended to the 
     # task's expected time plus 30 minutes.
     task_url = '%srecipes/%s/tasks/%s/' % (self.get_proxy_url(),
             self.recipe.id, self.recipe.tasks[1].id)
     response = requests.patch(task_url, data=dict(status='Running'))
     response.raise_for_status()
     with session.begin():
         self.assertEquals(self.recipe.tasks[1].task.avg_time, 1200)
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=3000))
Exemplo n.º 13
0
 def test_initial_watchdog_set_correctly(self):
     # When a task is started the watchdog is implicitly extended to the
     # task's expected time plus 30 minutes.
     task_url = '%srecipes/%s/tasks/%s/' % (
         self.get_proxy_url(), self.recipe.id, self.recipe.tasks[1].id)
     response = requests.patch(task_url, data=dict(status='Running'))
     response.raise_for_status()
     with session.begin():
         self.assertEquals(self.recipe.tasks[1].task.avg_time, 1200)
         assert_datetime_within(self.recipe.watchdog.kill_time,
                                tolerance=datetime.timedelta(seconds=10),
                                reference=datetime.datetime.utcnow() +
                                datetime.timedelta(seconds=3000))
Exemplo n.º 14
0
 def test_watchdog_extend_by_recipe(self):
     run_client(['bkr','watchdog-extend', '--by=600', self.recipe.t_id])
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
     # nonexistent recipe
     try:
         run_client(['bkr', 'watchdog-extend', 'R:0'])
         self.fail('Must raise')
     except ClientError as e:
         self.assertIn('0 is not a valid Recipe id', e.stderr_output)
Exemplo n.º 15
0
 def test_add_note(self):
     note_text = 'sometimes it breaks'
     s = requests.Session()
     requests_login(s, user=self.owner.user_name, password=u'owner')
     response = post_json(get_server_base() + 'systems/%s/notes/' % self.system.fqdn,
             session=s, data={'text': note_text})
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertEquals(self.system.notes[0].user, self.owner)
         self.assertEquals(self.system.notes[0].text, note_text)
         assert_datetime_within(self.system.notes[0].created,
                 reference=datetime.datetime.utcnow(),
                 tolerance=datetime.timedelta(seconds=10))
Exemplo n.º 16
0
 def test_watchdog_extend_by_recipe(self):
     run_client(['bkr', 'watchdog-extend', '--by=600', self.recipe.t_id])
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                                tolerance=datetime.timedelta(seconds=10),
                                reference=datetime.datetime.utcnow() +
                                datetime.timedelta(seconds=600))
     # nonexistent recipe
     try:
         run_client(['bkr', 'watchdog-extend', 'R:0'])
         self.fail('Must raise')
     except ClientError as e:
         self.assertIn('0 is not a valid Recipe id', e.stderr_output)
Exemplo n.º 17
0
 def test_install_start(self):
     with session.begin():
         system = data_setup.create_system(lab_controller=self.lc)
         recipe = data_setup.create_recipe()
         data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_waiting(recipe, system=system)
     self.server.recipes.install_start(recipe.id)
     with session.begin():
         session.expire_all()
         assert_datetime_within(recipe.installation.install_started,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow())
         assert_datetime_within(recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(hours=3))
Exemplo n.º 18
0
 def test_install_start(self):
     with session.begin():
         system = data_setup.create_system(lab_controller=self.lc)
         recipe = data_setup.create_recipe()
         data_setup.create_job_for_recipes([recipe])
         data_setup.mark_recipe_waiting(recipe, system=system)
     self.server.auth.login_password(self.lc.user.user_name, u'logmein')
     self.server.recipes.install_start(recipe.id)
     with session.begin():
         session.expire_all()
         assert_datetime_within(recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(hours=3))
         self.assertEqual(recipe.tasks[0].results[0].result, TaskResult.pass_)
         self.assertEqual(recipe.tasks[0].results[0].path, u'/start')
         self.assertEqual(recipe.tasks[0].results[0].log, u'Install Started')
Exemplo n.º 19
0
 def test_add_note(self):
     note_text = 'sometimes it breaks'
     s = requests.Session()
     requests_login(s, user=self.owner.user_name, password=u'owner')
     response = post_json(get_server_base() +
                          'systems/%s/notes/' % self.system.fqdn,
                          session=s,
                          data={'text': note_text})
     response.raise_for_status()
     with session.begin():
         session.expire_all()
         self.assertEquals(self.system.notes[0].user, self.owner)
         self.assertEquals(self.system.notes[0].text, note_text)
         assert_datetime_within(self.system.notes[0].created,
                                reference=datetime.datetime.utcnow(),
                                tolerance=datetime.timedelta(seconds=10))
Exemplo n.º 20
0
 def test_can_fetch_history(self):
     with session.begin():
         owner = data_setup.create_user()
         system = data_setup.create_system(owner=owner)
         system.activity.append(SystemActivity(user=owner, service=u'WEBUI',
                 action=u'Changed', field_name=u'fqdn',
                 old_value=u'oldname.example.com', new_value=system.fqdn))
     result = self.server.systems.history(system.fqdn)
     self.assertEquals(len(result), 1)
     assert_datetime_within(result[0]['created'],
             datetime.timedelta(seconds=5),
             reference=datetime.datetime.utcnow())
     self.assertEquals(result[0]['user'], owner.user_name)
     self.assertEquals(result[0]['service'], u'WEBUI')
     self.assertEquals(result[0]['action'], u'Changed')
     self.assertEquals(result[0]['field_name'], u'fqdn')
     self.assertEquals(result[0]['old_value'], u'oldname.example.com')
     self.assertEquals(result[0]['new_value'], system.fqdn)
Exemplo n.º 21
0
 def test_authenticated_user_can_extend_reservation(self):
     with session.begin():
         data_setup.mark_recipe_tasks_finished(self.recipe, only=True)
         self.job.update_status()
     b = self.browser
     login(b)
     go_to_recipe_view(b, self.recipe, tab='Reservation')
     tab = b.find_element_by_id('reservation')
     tab.find_element_by_xpath('.//button[contains(text(), "Extend the reservation")]')\
             .click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_name('kill_time').clear()
     modal.find_element_by_name('kill_time').send_keys('600')
     modal.find_element_by_xpath('.//button[text()="Save changes"]').click()
     b.find_element_by_xpath('//body[not(.//div[contains(@class, "modal")])]')
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
Exemplo n.º 22
0
 def test_authenticated_user_can_extend_reservation(self):
     with session.begin():
         data_setup.mark_recipe_tasks_finished(self.recipe, only=True)
         self.job.update_status()
     b = self.browser
     login(b)
     go_to_recipe_view(b, self.recipe, tab='Reservation')
     tab = b.find_element_by_id('reservation')
     tab.find_element_by_xpath('.//button[contains(text(), "Extend the reservation")]')\
             .click()
     modal = b.find_element_by_class_name('modal')
     modal.find_element_by_name('kill_time').clear()
     modal.find_element_by_name('kill_time').send_keys('600')
     modal.find_element_by_xpath('.//button[text()="Save changes"]').click()
     b.find_element_by_xpath('//body[not(.//div[contains(@class, "modal")])]')
     with session.begin():
         session.expire_all()
         assert_datetime_within(self.recipe.watchdog.kill_time,
                 tolerance=datetime.timedelta(seconds=10),
                 reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
Exemplo n.º 23
0
    def test_watchdog_extend_by_fqdn(self):
        with session.begin():
            lc = data_setup.create_labcontroller()
            system = data_setup.create_system(lab_controller=lc)
            recipe = data_setup.create_recipe()
            data_setup.create_job_for_recipes([recipe ])
            data_setup.mark_recipe_running(recipe , system=system)

        run_client(['bkr','watchdog-extend', '--by=600', system.fqdn])

        with session.begin():
            session.expire_all()
            assert_datetime_within(recipe.watchdog.kill_time,
                    tolerance=datetime.timedelta(seconds=10),
                    reference=datetime.datetime.utcnow() + datetime.timedelta(seconds=600))
        # nonexistent fqdn
        try:
            run_client(['bkr', 'watchdog-extend', 'ireallydontexistblah.test.fqdn'])
            self.fail('Must raise')
        except ClientError as e:
            self.assertIn('Cannot find any recipe running on ireallydontexistblah.test.fqdn', e.stderr_output)
Exemplo n.º 24
0
 def test_change_status(self):
     orig_date_modified = self.system.date_modified
     self.login()
     sel = self.selenium
     self.go_to_system_edit()
     sel.select("status", u"Broken")
     sel.click("link=Save Changes")
     sel.wait_for_page_to_load("30000")
     self.assert_system_view_text("status", u"Broken")
     with session.begin():
         session.refresh(self.system)
         self.assertEqual(self.system.status, SystemStatus.broken)
         self.assertEqual(len(self.system.status_durations), 2)
         self.assertEqual(self.system.status_durations[0].status, SystemStatus.broken)
         assertions.assert_datetime_within(
             self.system.status_durations[0].start_time,
             tolerance=datetime.timedelta(seconds=60),
             reference=datetime.datetime.utcnow(),
         )
         self.assert_(self.system.status_durations[0].finish_time is None)
         self.assert_(self.system.status_durations[1].finish_time is not None)
         assertions.assert_durations_not_overlapping(self.system.status_durations)
         self.assert_(self.system.date_modified > orig_date_modified)
Exemplo n.º 25
0
 def test_change_status(self):
     orig_date_modified = self.system.date_modified
     b = self.browser
     login(b)
     self.go_to_system_edit()
     Select(b.find_element_by_name('status')).select_by_visible_text('Broken')
     b.find_element_by_link_text('Save Changes').click()
     self.assert_system_view_text('status', u'Broken')
     with session.begin():
         session.refresh(self.system)
         self.assertEqual(self.system.status, SystemStatus.broken)
         self.assertEqual(len(self.system.status_durations), 2)
         self.assertEqual(self.system.status_durations[0].status,
                 SystemStatus.broken)
         assertions.assert_datetime_within(
                 self.system.status_durations[0].start_time,
                 tolerance=datetime.timedelta(seconds=60),
                 reference=datetime.datetime.utcnow())
         self.assert_(self.system.status_durations[0].finish_time is None)
         self.assert_(self.system.status_durations[1].finish_time is not None)
         assertions.assert_durations_not_overlapping(
                 self.system.status_durations)
         self.assert_(self.system.date_modified > orig_date_modified)
Exemplo n.º 26
0
 def test_mark_note_as_deleted(self):
     # Notes never get actually deleted, they just get marked as "deleted" 
     # which hides them by default in the UI. "Obsoleted" would be a better 
     # word but "deleted" is what we have.
     with session.begin():
         note_text = u'some obsolete info'
         self.system.notes.append(Note(text=note_text, user=self.owner))
         session.flush()
         note_id = self.system.notes[0].id
     s = requests.Session()
     requests_login(s, user=self.owner.user_name, password=u'owner')
     response = patch_json(get_server_base() + 'systems/%s/notes/%s'
             % (self.system.fqdn, note_id), session=s, data={'deleted': 'now'})
     response.raise_for_status()
     self.assertEquals(response.json()['id'], note_id)
     assert_datetime_within(
             datetime.datetime.strptime(response.json()['deleted'], '%Y-%m-%d %H:%M:%S'),
             reference=datetime.datetime.utcnow(),
             tolerance=datetime.timedelta(seconds=10))
     with session.begin():
         session.refresh(self.system.notes[0])
         assert_datetime_within(self.system.notes[0].deleted,
                 reference=datetime.datetime.utcnow(),
                 tolerance=datetime.timedelta(seconds=10))