Пример #1
0
    def test_get_member_ports(self, mock_get_net_driver):
        mock_driver = mock.MagicMock()
        mock_get_net_driver.return_value = mock_driver

        def _interface(port_id):
            return [data_models.Interface(port_id=port_id)]

        net_task = network_tasks.GetMemberPorts()
        net_task.execute(LB, self.amphora_mock)
        mock_driver.get_port.assert_called_once_with(t_constants.MOCK_PORT_ID)
        mock_driver.get_plugged_networks.assert_called_once_with(COMPUTE_ID)

        mock_driver.reset_mock()
        net_task = network_tasks.GetMemberPorts()
        mock_driver.get_plugged_networks.return_value = _interface(1)
        mock_driver.get_port.side_effect = [
            data_models.Port(network_id=NETWORK_ID),
            data_models.Port(network_id=NETWORK_ID)]
        net_task.execute(self.load_balancer_mock, self.amphora_mock)
        self.assertEqual(2, mock_driver.get_port.call_count)
        self.assertFalse(mock_driver.get_network.called)

        mock_driver.reset_mock()
        port_mock = mock.MagicMock()
        fixed_ip_mock = mock.MagicMock()
        fixed_ip_mock.subnet_id = 1
        port_mock.fixed_ips = [fixed_ip_mock]
        net_task = network_tasks.GetMemberPorts()
        mock_driver.get_plugged_networks.return_value = _interface(1)
        mock_driver.get_port.side_effect = [
            data_models.Port(network_id=NETWORK_ID), port_mock]
        ports = net_task.execute(self.load_balancer_mock, self.amphora_mock)
        mock_driver.get_subnet.assert_called_once_with(1)
        self.assertEqual([port_mock], ports)
Пример #2
0
    def get_failover_flow(self, role=constants.ROLE_STANDALONE):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(
            network_tasks.RetrievePortIDsOnAmphoraExceptLBNetwork(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA,
                provides=constants.PORTS))
        failover_amphora_flow.add(
            network_tasks.FailoverPreparationForAmphora(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # Delete the old amphora
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraPendingDeleteInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraHealthBusy(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.DisableAmphoraHealthMonitoring(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA))

        # Save failed amphora details for later
        failover_amphora_flow.add(
            database_tasks.GetAmphoraDetails(
                rebind={constants.AMPHORA: constants.FAILED_AMPHORA},
                requires=constants.AMPHORA,
                provides=constants.AMP_DATA))

        # Get a new amphora
        # Note: Role doesn't matter here.  We will update it later.
        get_amp_subflow = self.get_amphora_for_lb_subflow(
            prefix=constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(get_amp_subflow)

        # Update the new amphora with the failed amphora details
        failover_amphora_flow.add(
            database_tasks.UpdateAmpFailoverDetails(
                requires=(constants.AMPHORA, constants.AMP_DATA)))

        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))

        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))
        failover_amphora_flow.add(
            database_tasks.GetVipFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.VIP))
        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersUpdate(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))
        failover_amphora_flow.add(
            network_tasks.PlugPorts(requires=(constants.AMPHORA,
                                              constants.PORTS)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            network_tasks.GetMemberPorts(requires=(constants.LOADBALANCER,
                                                   constants.AMPHORA),
                                         provides=constants.MEMBER_PORTS))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostNetworkPlug(
                rebind={constants.PORTS: constants.MEMBER_PORTS},
                requires=(constants.AMPHORA, constants.PORTS)))

        # Handle the amphora role and VRRP if necessary
        if role == constants.ROLE_MASTER:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraMasterInDB(
                    name=constants.MARK_AMP_MASTER_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_BACKUP:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraBackupInDB(
                    name=constants.MARK_AMP_BACKUP_INDB,
                    requires=constants.AMPHORA))
            vrrp_subflow = self.get_vrrp_subflow(role)
            failover_amphora_flow.add(vrrp_subflow)
        elif role == constants.ROLE_STANDALONE:
            failover_amphora_flow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(
                requires=(constants.LOADBALANCER, constants.LISTENERS)))

        return failover_amphora_flow
Пример #3
0
    def get_failover_flow(self):
        """Creates a flow to failover a stale amphora

        :returns: The flow for amphora failover
        """

        failover_amphora_flow = linear_flow.Flow(
            constants.FAILOVER_AMPHORA_FLOW)
        failover_amphora_flow.add(
            network_tasks.RetrievePortIDsOnAmphoraExceptLBNetwork(
                requires=constants.AMPHORA, provides=constants.PORTS))
        failover_amphora_flow.add(
            network_tasks.FailoverPreparationForAmphora(
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            compute_tasks.ComputeDelete(requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraDeletedInDB(requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        failover_amphora_flow.add(
            database_tasks.GetUpdatedFailoverAmpNetworkDetailsAsList(
                requires=(constants.AMPHORA_ID, constants.AMPHORA),
                provides=constants.AMPS_DATA))
        if self.REST_AMPHORA_DRIVER:
            failover_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))
            failover_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM),
                    provides=constants.COMPUTE_ID))
        else:
            failover_amphora_flow.add(
                compute_tasks.ComputeCreate(requires=constants.AMPHORA_ID,
                                            provides=constants.COMPUTE_ID))
        failover_amphora_flow.add(
            database_tasks.UpdateAmphoraComputeId(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        failover_amphora_flow.add(
            database_tasks.AssociateFailoverAmphoraWithLBID(
                requires=(constants.AMPHORA_ID, constants.LOADBALANCER_ID)))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        wait_flow = linear_flow.Flow(
            constants.WAIT_FOR_AMPHORA,
            retry=retry.Times(CONF.controller_worker.amp_active_retries))
        wait_flow.add(
            compute_tasks.ComputeWait(requires=constants.COMPUTE_ID,
                                      provides=constants.COMPUTE_OBJ))
        wait_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        failover_amphora_flow.add(wait_flow)
        failover_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.FAILOVER_AMPHORA))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=constants.AMPHORA))
        failover_amphora_flow.add(
            database_tasks.UpdateAmphoraVIPData(requires=constants.AMPS_DATA))
        failover_amphora_flow.add(
            database_tasks.ReloadLoadBalancer(
                requires=constants.LOADBALANCER_ID,
                provides=constants.LOADBALANCER))
        failover_amphora_flow.add(
            network_tasks.GetAmphoraeNetworkConfigs(
                requires=constants.LOADBALANCER,
                provides=constants.AMPHORAE_NETWORK_CONFIG))
        failover_amphora_flow.add(
            database_tasks.GetListenersFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.LISTENERS))
        failover_amphora_flow.add(
            database_tasks.GetVipFromLoadbalancer(
                requires=constants.LOADBALANCER, provides=constants.VIP))
        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersUpdate(requires=(constants.LISTENERS,
                                                           constants.VIP)))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostVIPPlug(
                requires=(constants.LOADBALANCER,
                          constants.AMPHORAE_NETWORK_CONFIG)))
        failover_amphora_flow.add(
            network_tasks.GetMemberPorts(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=(constants.LOADBALANCER, constants.AMPHORA),
                provides=constants.MEMBER_PORTS))
        failover_amphora_flow.add(
            amphora_driver_tasks.AmphoraPostNetworkPlug(
                rebind={
                    constants.AMPHORA: constants.FAILOVER_AMPHORA,
                    constants.PORTS: constants.MEMBER_PORTS
                },
                requires=(constants.AMPHORA, constants.PORTS)))
        failover_amphora_flow.add(
            amphora_driver_tasks.ListenersStart(requires=(constants.LISTENERS,
                                                          constants.VIP)))
        failover_amphora_flow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                rebind={constants.AMPHORA: constants.FAILOVER_AMPHORA},
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))

        return failover_amphora_flow