Exemple #1
0
 def test_process_labrequests(self):
     expected_lab = ("testlab", "sprint", "netact-3", False)
     testlabs = [("testlab-1", "sprint", "netact-5", False),
                 ("testlab2", "sprint", "netact-2", False),
                 ("testlab-2", "sprint", "netact-2", False), expected_lab,
                 ("2", "sprint", "netact-2", False),
                 ("lab-2", "sprint", "netact-2", False),
                 ("testlab-3", "cloud", "netact-1", False)]
     test_data.test_setup(testlabs, lab_status="ready")
     labs = test_data.get_resources('labs')['_items']
     expected_lab_ids = [
         lab['_id'] for lab in labs if lab['lab_name'] == expected_lab[0]
     ]
     self.assertEqual(len(expected_lab_ids), 1)
     expected_lab_id = expected_lab_ids.pop()
     labrequest_response = test_data.post_labrequest(
         "mikko", "{{\"build.id\": \"{0}\"}}".format(expected_lab[2]))
     labrequest_id = labrequest_response['_id']
     labrequest_data = test_data.get_resources('labrequests')['_items'][0]
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_data['username'], "mikko")
     self.assertEqual(labrequest_data['status'], "pending")
     labrequest_tasks.process_labrequests()
     labrequest_processed_data = test_data.get_item('labrequests',
                                                    labrequest_id)
     self.assertEqual(labrequest_processed_data['lab'], expected_lab_id)
     self.assertEqual(labrequest_processed_data['username'], "mikko")
     my_lab = test_data.get_item('labs', expected_lab_id)
     my_reservation = test_data.get_item('reservations',
                                         my_lab['reservation'])
     self.assertEqual(my_reservation['username'], "mikko")
     self.assertEqual(my_reservation['username'], "mikko")
     self.assertEqual(labrequest_processed_data['status'], "ready")
Exemple #2
0
 def test_process_labrequest_match_only_available_snapshots(self):
     expected_lab = ("testlab", "sprint", "netact-3", False)
     testlabs = [("testlab-1", "sprint", "netact-5", False),
                 ("testlab2", "sprint", "netact-2", False),
                 ("testlab-2", "sprint", "netact-2", False), expected_lab,
                 ("2", "sprint", "netact-2", False),
                 ("lab-2", "sprint", "netact-2", False),
                 ("testlab-3", "cloud", "netact-1", False)]
     test_data.test_setup(testlabs, snapshots_status="failed")
     labs = test_data.get_resources('labs')['_items']
     expected_lab_ids = [
         lab['_id'] for lab in labs if lab['lab_name'] == expected_lab[0]
     ]
     self.assertEqual(len(expected_lab_ids), 1)
     labrequest_response = test_data.post_labrequest(
         "mikko", "{{\"build.id\": \"{0}\"}}".format(expected_lab[2]))
     labrequest_id = labrequest_response['_id']
     labrequest_data = test_data.get_item('labrequests', labrequest_id)
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_data['username'], "mikko")
     self.assertEqual(labrequest_data['status'], "pending")
     labrequest_tasks.LabrequestProcessor(
         labrequest_data).process_labrequest()
     labrequest_processed_data = test_data.get_item('labrequests',
                                                    labrequest_id)
     self.assertEqual(labrequest_processed_data.get('status'),
                      "no_lab_available")
     self.assertIsNone(labrequest_processed_data.get('lab'))
Exemple #3
0
 def test_get_resource_items(self):
     testlabs = [("testlab-1", "sprint", "netact-5", False),
                 ("testlab-2", "sprint", "netact-2", False),
                 ("testlab-3", "sprint", "netact-2", False),
                 ("testlab-4", "sprint", "netact-2", False),
                 ("testlab-5", "sprint", "netact-2", False),
                 ("testlab-6", "sprint", "netact-2", False),
                 ("testlab-7", "cloud", "netact-1", False)]
     test_data.test_setup(testlabs)
     items = labrequest_tasks._get_all_resource_items('labs',
                                                      all_pages=True,
                                                      max_results=1)
     self.assertEqual(len(items), len(testlabs))
     items = labrequest_tasks._get_all_resource_items('labs',
                                                      all_pages=True)
     self.assertEqual(len(items), len(testlabs))
     items = labrequest_tasks._get_all_resource_items('labs',
                                                      all_pages=False)
     self.assertEqual(len(items), len(testlabs))
     items = labrequest_tasks._get_all_resource_items('labs',
                                                      all_pages=False,
                                                      max_results=1)
     self.assertEqual(len(items), 1)
     items = labrequest_tasks._get_all_resource_items('labs')
     self.assertEqual(len(items), len(testlabs))
     items = labrequest_tasks._get_all_resource_items('labs',
                                                      all_pages=True,
                                                      max_results=2)
     self.assertEqual(len(items), len(testlabs))
     self.assertEqual(items[3]['lab_name'], "testlab-4")
Exemple #4
0
    def test_process_labrequests_concurrency_problem(self):
        # It's possible that labrequest processing and keepalive are both updating labrequest at the same time.
        # Both are now supporting retry in case of etag mismatch that seems to help and should tackle all meaningful scenarios.
        # i.e. where keepalive is called by one client once per second etc.
        #
        # There's still some problem that causes labrequest processing to add a lab even when the request itself seems to be successful.
        # To reproduce, increase the number of keepalive_threads.
        expected_lab = ("testlab", "sprint", "netact-3", False)
        testlabs = [("testlab-1", "sprint", "netact-5", False),
                    ("testlab2", "sprint", "netact-2", False),
                    ("testlab-2", "sprint", "netact-2", False), expected_lab,
                    ("2", "sprint", "netact-2", False),
                    ("lab-2", "sprint", "netact-2", False),
                    ("testlab-3", "cloud", "netact-1", False)]
        test_data.test_setup(testlabs, lab_status="ready")
        labs = test_data.get_resources('labs')['_items']
        expected_lab_ids = [
            lab['_id'] for lab in labs if lab['lab_name'] == expected_lab[0]
        ]
        self.assertEqual(len(expected_lab_ids), 1)
        expected_lab_id = expected_lab_ids.pop()
        labrequest_response = test_data.post_labrequest(
            "mikko", "{{\"build.id\": \"{0}\"}}".format(expected_lab[2]))
        labrequest_id = labrequest_response['_id']
        labrequest_data = test_data.get_resources('labrequests')['_items'][0]
        self.assertIsNone(labrequest_data.get('lab'))
        self.assertEqual(labrequest_data['username'], "mikko")
        self.assertEqual(labrequest_data['status'], "pending")

        def _process():
            labrequest_tasks.process_labrequests()

        def _keepalive():
            requests.patch("{}/{}/{}/keepalive".format(STATE_REST_API_URL,
                                                       'labrequests',
                                                       labrequest_id))

        process = threading.Thread(target=_process)
        keepalive_threads = []
        for i in xrange(1, 10):
            keepalive_threads.append(threading.Thread(target=_keepalive))
        process.start()
        for thread in keepalive_threads:
            thread.start()
        process.join()
        for thread in keepalive_threads:
            thread.join()
        labrequest_processed_data = test_data.get_item('labrequests',
                                                       labrequest_id)
        self.assertEqual(labrequest_processed_data['lab'], expected_lab_id)
        self.assertEqual(labrequest_processed_data['username'], "mikko")
        my_lab = test_data.get_item('labs', expected_lab_id)
        my_reservation = test_data.get_item('reservations',
                                            my_lab['reservation'])
        self.assertEqual(my_reservation['username'], "mikko")
        self.assertEqual(my_reservation['username'], "mikko")
        self.assertEqual(labrequest_processed_data['status'], "ready")
Exemple #5
0
 def _test_process_labrequest_extend_duration_setup(self, duration):
     ''' setup some labs and reserve one of them '''
     test_data.test_setup([
         ("testlab-1", "sprint", "netact-5", False),
         ("testlab-2", "sprint", "netact-5", False),
         ("testlab-3", "sprint", "netact-7", False),
     ])
     return self._do_reserve_lab(
         'X',
         '{"build.id": "netact-7"}',
         message='test_process_labrequest_extend_duration',
         expected_state='ready',
         duration=str(duration))
Exemple #6
0
    def _exec_test_process_labrequest_successful_reservation(
            self, **more_labrequest_settings):
        expected_lab = ("testlab", "sprint", "netact-3", False)
        testlabs = [("testlab-1", "sprint", "netact-5", False),
                    ("testlab2", "sprint", "netact-2", False),
                    ("testlab-2", "sprint", "netact-2", False), expected_lab,
                    ("2", "sprint", "netact-2", False),
                    ("lab-2", "sprint", "netact-2", False),
                    ("testlab-3", "cloud", "netact-1", False)]
        test_data.test_setup(testlabs, lab_status="ready")

        query = json.dumps({'build.id': expected_lab[2]})
        reservation = self._do_reserve_lab("mikko",
                                           query,
                                           expected_state='ready',
                                           **more_labrequest_settings)
        return reservation
Exemple #7
0
 def test_process_labrequest_no_lab_available_no_final_state(self):
     testlabs = [("testlab-1", "sprint", "netact-5", False),
                 ("lab-2", "sprint", "netact-2", False),
                 ("testlab-3", "cloud", "netact-1", False)]
     test_data.test_setup(testlabs, lab_status="reverting_state")
     labrequest_response = test_data.post_labrequest(
         "mikko", "{{\"build.id\": \"{0}\"}}".format("netact-1"))
     labrequest_id = labrequest_response['_id']
     labrequest_data = test_data.get_item('labrequests', labrequest_id)
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_data['username'], "mikko")
     self.assertEqual(labrequest_data['status'], "pending")
     labrequest_tasks.LabrequestProcessor(
         labrequest_data).process_labrequest()
     labrequest_processed_data = test_data.get_item('labrequests',
                                                    labrequest_id)
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_processed_data['username'], "mikko")
     self.assertEqual(labrequest_processed_data['status'],
                      "no_lab_available")
Exemple #8
0
 def test_process_labrequest_no_matching_lab(self):
     testlabs = [("testlab-1", "sprint", "netact-5", True),
                 ("lab-2", "sprint", "netact-2", True),
                 ("testlab-3", "cloud", "netact-1", True)]
     test_data.test_setup(testlabs)
     labrequest_response = test_data.post_labrequest(
         "mikko",
         "{{\"build.id\": \"{0}\"}}".format("netact-1"),
         lab_search_query="lab_type==sprint")
     labrequest_id = labrequest_response['_id']
     labrequest_data = test_data.get_item('labrequests', labrequest_id)
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_data['username'], "mikko")
     self.assertEqual(labrequest_data['status'], "pending")
     labrequest_tasks.LabrequestProcessor(
         labrequest_data).process_labrequest()
     labrequest_processed_data = test_data.get_item('labrequests',
                                                    labrequest_id)
     self.assertIsNone(labrequest_data.get('lab'))
     self.assertEqual(labrequest_processed_data['username'], "mikko")
     self.assertEqual(labrequest_processed_data['status'],
                      "no_matching_state")