Exemple #1
0
    def update_ports_for_sg(self, context, portid, jobid):
        """Updates the ports through redis."""
        port = db_api.port_find(context, id=portid, scope=db_api.ONE)
        if not port:
            LOG.warning("Port not found")
            return
        net_driver = port_api._get_net_driver(port.network, port=port)
        base_net_driver = port_api._get_net_driver(port.network)
        sg_list = [sg for sg in port.security_groups]

        success = False
        error = None
        retries = 3
        retry_delay = 2
        for retry in xrange(retries):
            try:
                net_driver.update_port(context, port_id=port["backend_key"],
                                       mac_address=port["mac_address"],
                                       device_id=port["device_id"],
                                       base_net_driver=base_net_driver,
                                       security_groups=sg_list)
                success = True
                error = None
                break
            except Exception as error:
                LOG.warning("Could not connect to redis, but retrying soon")
                time.sleep(retry_delay)
        status_str = ""
        if not success:
            status_str = "Port %s update failed after %d tries. Error: %s" % (
                portid, retries, error)
        update_body = dict(completed=True, status=status_str)
        update_body = dict(job=update_body)
        job_api.update_job(context.elevated(), jobid, update_body)
Exemple #2
0
    def test_transaction_completion_percent(self):
        job_body = dict(tenant_id=self.tenant_id,
                        action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        parent_job = job_api.create_job(self.admin_context, job_body)
        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertIsNotNone(parent_job)
        job_body = dict(tenant_id=self.tenant_id,
                        action=self.action,
                        completed=False,
                        parent_id=parent_job['id'])
        job_body = dict(job=job_body)
        job = job_api.create_job(self.admin_context, job_body)
        job = job_api.get_job(self.admin_context, job['id'])
        self.assertIsNotNone(job)

        job_body = dict(tenant_id=self.tenant_id,
                        action=self.action,
                        completed=False,
                        parent_id=job['id'])
        job_body = dict(job=job_body)
        subjob = job_api.create_job(self.admin_context, job_body)
        subjob = job_api.get_job(self.admin_context, subjob['id'])
        self.assertIsNotNone(job)

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertTrue('transaction_percent' in parent_job)
        self.assertEqual(0, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(0, parent_job['completed_subtransactions'])

        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        subjob = job_api.update_job(self.admin_context, subjob['id'],
                                    update_body)
        self.assertTrue(subjob['completed'])

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertEqual(50, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(1, parent_job['completed_subtransactions'])

        job = job_api.update_job(self.admin_context, job['id'], update_body)
        self.assertTrue(subjob['completed'])

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertEqual(100, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(2, parent_job['completed_subtransactions'])
        self.assertEqual(True, parent_job['completed'])
Exemple #3
0
    def test_transaction_completion_percent(self):
        job_body = dict(tenant_id=self.tenant_id, action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        parent_job = job_api.create_job(self.admin_context, job_body)
        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertIsNotNone(parent_job)
        job_body = dict(tenant_id=self.tenant_id, action=self.action,
                        completed=False, parent_id=parent_job['id'])
        job_body = dict(job=job_body)
        job = job_api.create_job(self.admin_context, job_body)
        job = job_api.get_job(self.admin_context, job['id'])
        self.assertIsNotNone(job)

        job_body = dict(tenant_id=self.tenant_id, action=self.action,
                        completed=False, parent_id=job['id'])
        job_body = dict(job=job_body)
        subjob = job_api.create_job(self.admin_context, job_body)
        subjob = job_api.get_job(self.admin_context, subjob['id'])
        self.assertIsNotNone(job)

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertTrue('transaction_percent' in parent_job)
        self.assertEqual(0, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(0, parent_job['completed_subtransactions'])

        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        subjob = job_api.update_job(self.admin_context, subjob['id'],
                                    update_body)
        self.assertTrue(subjob['completed'])

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertEqual(50, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(1, parent_job['completed_subtransactions'])

        job = job_api.update_job(self.admin_context, job['id'], update_body)
        self.assertTrue(subjob['completed'])

        parent_job = job_api.get_job(self.admin_context, parent_job['id'])
        self.assertEqual(100, parent_job['transaction_percent'])
        self.assertEqual(2, parent_job['subtransactions'])
        self.assertEqual(2, parent_job['completed_subtransactions'])
        self.assertEqual(True, parent_job['completed'])
Exemple #4
0
    def test_update_job_fail_non_admin(self):
        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        job_body = dict(tenant_id=self.tenant_id, action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        job1 = job_api.create_job(self.admin_context, job_body)
        self.assertIsNotNone(job1)

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertFalse(job['completed'])

        with self.assertRaises(n_exc.NotAuthorized):
            job_api.update_job(self.context, job1['id'], update_body)

        updated_job = job_api.update_job(self.admin_context, job1['id'],
                                         update_body)
        self.assertTrue(updated_job['completed'])

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertTrue(job['completed'])
Exemple #5
0
    def test_update_jobs(self):
        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        with self.assertRaises(q_exc.JobNotFound):
            job_api.update_job(self.admin_context, 'derp', update_body)

        job_body = dict(tenant_id=self.tenant_id, action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        job1 = job_api.create_job(self.admin_context, job_body)
        self.assertIsNotNone(job1)

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertFalse(job['completed'])

        updated_job = job_api.update_job(self.admin_context, job1['id'],
                                         update_body)
        self.assertTrue(updated_job['completed'])

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertTrue(job['completed'])
Exemple #6
0
    def test_update_job_fail_non_admin(self):
        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        job_body = dict(tenant_id=self.tenant_id,
                        action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        job1 = job_api.create_job(self.admin_context, job_body)
        self.assertIsNotNone(job1)

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertFalse(job['completed'])

        with self.assertRaises(n_exc.NotAuthorized):
            job_api.update_job(self.context, job1['id'], update_body)

        updated_job = job_api.update_job(self.admin_context, job1['id'],
                                         update_body)
        self.assertTrue(updated_job['completed'])

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertTrue(job['completed'])
Exemple #7
0
    def test_update_jobs(self):
        update_body = dict(completed=True)
        update_body = dict(job=update_body)

        with self.assertRaises(q_exc.JobNotFound):
            job_api.update_job(self.admin_context, 'derp', update_body)

        job_body = dict(tenant_id=self.tenant_id,
                        action=self.action,
                        completed=False)
        job_body = dict(job=job_body)
        job1 = job_api.create_job(self.admin_context, job_body)
        self.assertIsNotNone(job1)

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertFalse(job['completed'])

        updated_job = job_api.update_job(self.admin_context, job1['id'],
                                         update_body)
        self.assertTrue(updated_job['completed'])

        job = job_api.get_job(self.admin_context, job1['id'])
        self.assertTrue(job['completed'])
Exemple #8
0
 def update_job(self, context, id, job):
     self._fix_missing_tenant_id(context, job, 'job')
     return jobs.update_job(context, id, job)
Exemple #9
0
 def update_job(self, context, id, job):
     self._fix_missing_tenant_id(context, job, 'job')
     return jobs.update_job(context, id, job)