Ejemplo n.º 1
0
    def test_HM_to_provider_HM_with_http_version_and_domain_name(self):
        provider_hm = utils.db_HM_to_provider_HM(self.sample_data.db_hm2)
        self.assertEqual(self.sample_data.provider_hm2, provider_hm)

        provider_hm_dict = utils.hm_dict_to_provider_dict(
            self.sample_data.test_hm2_dict)
        self.assertEqual(self.sample_data.provider_hm2_dict, provider_hm_dict)
Ejemplo n.º 2
0
    def test_HM_to_provider_HM_with_http_version_and_domain_name(self):
        provider_hm = utils.db_HM_to_provider_HM(self.sample_data.db_hm2)
        self.assertEqual(self.sample_data.provider_hm2, provider_hm)

        provider_hm_dict = utils.hm_dict_to_provider_dict(
            self.sample_data.test_hm2_dict)
        self.assertEqual(self.sample_data.provider_hm2_dict, provider_hm_dict)
Ejemplo n.º 3
0
    def put(self, id, health_monitor_):
        """Updates a health monitor."""
        context = pecan_request.context.get('octavia_context')
        health_monitor = health_monitor_.healthmonitor
        db_hm = self._get_db_hm(context.session, id, show_deleted=False)

        pool = self._get_db_pool(context.session, db_hm.pool_id)
        project_id, provider = self._get_lb_project_id_provider(
            context.session, pool.load_balancer_id)

        self._auth_validate_action(context, project_id, consts.RBAC_PUT)

        self._validate_update_hm(db_hm, health_monitor)
        # Validate health monitor update options for UDP/SCTP
        if pool.protocol in (lib_consts.PROTOCOL_UDP,
                             lib_consts.PROTOCOL_SCTP):
            health_monitor.type = db_hm.type
            self._validate_healthmonitor_request_for_udp_sctp(
                health_monitor, pool.protocol)

        self._set_default_on_none(health_monitor)

        # Load the driver early as it also provides validation
        driver = driver_factory.get_driver(provider)

        with db_api.get_lock_session() as lock_session:

            self._test_lb_and_listener_and_pool_statuses(lock_session, db_hm)

            # Prepare the data for the driver data model
            healthmon_dict = health_monitor.to_dict(render_unsets=False)
            healthmon_dict['id'] = id
            provider_healthmon_dict = (
                driver_utils.hm_dict_to_provider_dict(healthmon_dict))

            # Also prepare the baseline object data
            old_provider_healthmon = driver_utils.db_HM_to_provider_HM(db_hm)

            # Dispatch to the driver
            LOG.info("Sending update Health Monitor %s to provider %s", id,
                     driver.name)
            driver_utils.call_provider(
                driver.name, driver.health_monitor_update,
                old_provider_healthmon,
                driver_dm.HealthMonitor.from_dict(provider_healthmon_dict))

            # Update the database to reflect what the driver just accepted
            health_monitor.provisioning_status = consts.PENDING_UPDATE
            db_hm_dict = health_monitor.to_dict(render_unsets=False)
            self.repositories.health_monitor.update(lock_session, id,
                                                    **db_hm_dict)

        # Force SQL alchemy to query the DB, otherwise we get inconsistent
        # results
        context.session.expire_all()
        db_hm = self._get_db_hm(context.session, id)
        result = self._convert_db_to_type(db_hm,
                                          hm_types.HealthMonitorResponse)
        return hm_types.HealthMonitorRootResponse(healthmonitor=result)
Ejemplo n.º 4
0
 def test_hm_dict_to_provider_dict_partial(self):
     provider_hm_dict = utils.hm_dict_to_provider_dict({'id': 1})
     self.assertEqual({'healthmonitor_id': 1}, provider_hm_dict)
Ejemplo n.º 5
0
 def test_hm_dict_to_provider_dict(self):
     provider_hm_dict = utils.hm_dict_to_provider_dict(
         self.sample_data.test_hm1_dict)
     self.assertEqual(self.sample_data.provider_hm1_dict, provider_hm_dict)
Ejemplo n.º 6
0
 def test_hm_dict_to_provider_dict_partial(self):
     provider_hm_dict = utils.hm_dict_to_provider_dict({'id': 1})
     self.assertEqual({'healthmonitor_id': 1}, provider_hm_dict)
Ejemplo n.º 7
0
 def test_hm_dict_to_provider_dict(self):
     provider_hm_dict = utils.hm_dict_to_provider_dict(
         self.sample_data.test_hm1_dict)
     self.assertEqual(self.sample_data.provider_hm1_dict, provider_hm_dict)