def test_compute_create_without_ssh_access(self, mock_driver, mock_conf,
                                               mock_jinja, mock_log_cfg):

        createcompute = compute_tasks.ComputeCreate()

        mock_driver.build.return_value = COMPUTE_ID
        self.conf.config(group="controller_worker",
                         amp_ssh_access_allowed=False)
        self.conf.config(group="controller_worker",
                         user_data_config_drive=False)
        mock_log_cfg.return_value = 'FAKE CFG'

        # Test execute()
        compute_id = createcompute.execute(_db_amphora_mock.id,
                                           ports=[_port],
                                           server_group_id=SERVER_GRPOUP_ID)

        # Validate that the build method was called properly
        mock_driver.build.assert_called_once_with(
            name="amphora-" + _db_amphora_mock.id,
            amphora_flavor=AMP_FLAVOR_ID,
            image_id=AMP_IMAGE_ID,
            image_tag=AMP_IMAGE_TAG,
            image_owner='',
            key_name=None,
            sec_groups=AMP_SEC_GROUPS,
            network_ids=AMP_NET,
            port_ids=[PORT_ID],
            config_drive_files={
                '/etc/octavia/'
                'amphora-agent.conf': 'test_conf',
                '/etc/rsyslog.d/10-rsyslog.conf': 'FAKE CFG'
            },
            user_data=None,
            server_group_id=SERVER_GRPOUP_ID,
            availability_zone=None)

        self.assertEqual(COMPUTE_ID, compute_id)

        # Test that a build exception is raised
        createcompute = compute_tasks.ComputeCreate()

        self.assertRaises(TypeError,
                          createcompute.execute,
                          _db_amphora_mock,
                          config_drive_files='test_cert')

        # Test revert()

        _db_amphora_mock.compute_id = COMPUTE_ID

        createcompute = compute_tasks.ComputeCreate()
        createcompute.revert(compute_id, _db_amphora_mock.id)

        # Validate that the delete method was called properly
        mock_driver.delete.assert_called_once_with(COMPUTE_ID)

        # Test that a delete exception is not raised

        createcompute.revert(COMPUTE_ID, _db_amphora_mock.id)
Beispiel #2
0
    def test_compute_create_cert(self, mock_driver, mock_conf, mock_jinja,
                                 mock_log_cfg):
        createcompute = compute_tasks.CertComputeCreate()
        key = utils.get_six_compatible_server_certs_key_passphrase()
        fer = fernet.Fernet(key)
        mock_log_cfg.return_value = 'FAKE CFG'

        mock_driver.build.return_value = COMPUTE_ID
        path = '/etc/octavia/certs/ca_01.pem'
        self.useFixture(test_utils.OpenFixture(path, 'test'))
        # Test execute()
        test_cert = fer.encrypt(utils.get_six_compatible_value('test_cert'))
        compute_id = createcompute.execute(_amphora_mock.id,
                                           test_cert,
                                           server_group_id=SERVER_GRPOUP_ID)

        # Validate that the build method was called properly
        mock_driver.build.assert_called_once_with(
            name="amphora-" + _amphora_mock.id,
            amphora_flavor=AMP_FLAVOR_ID,
            image_id=AMP_IMAGE_ID,
            image_tag=AMP_IMAGE_TAG,
            image_owner='',
            key_name=AMP_SSH_KEY_NAME,
            sec_groups=AMP_SEC_GROUPS,
            network_ids=AMP_NET,
            port_ids=[],
            user_data=None,
            config_drive_files={
                '/etc/rsyslog.d/10-rsyslog.conf': 'FAKE CFG',
                '/etc/octavia/certs/server.pem': fer.decrypt(test_cert),
                '/etc/octavia/certs/client_ca.pem': 'test',
                '/etc/octavia/amphora-agent.conf': 'test_conf'
            },
            server_group_id=SERVER_GRPOUP_ID)

        self.assertEqual(COMPUTE_ID, compute_id)

        # Test that a build exception is raised
        self.useFixture(test_utils.OpenFixture(path, 'test'))

        createcompute = compute_tasks.ComputeCreate()
        self.assertRaises(TypeError,
                          createcompute.execute,
                          _amphora_mock,
                          config_drive_files=test_cert)

        # Test revert()

        _amphora_mock.compute_id = COMPUTE_ID

        createcompute = compute_tasks.ComputeCreate()
        createcompute.revert(compute_id, _amphora_mock.id)

        # Validate that the delete method was called properly
        mock_driver.delete.assert_called_once_with(COMPUTE_ID)

        # Test that a delete exception is not raised

        createcompute.revert(COMPUTE_ID, _amphora_mock.id)
Beispiel #3
0
    def test_compute_create(self, mock_driver, mock_conf, mock_jinja,
                            mock_log_cfg):

        image_owner_id = uuidutils.generate_uuid()
        self.conf.config(group="controller_worker",
                         amp_image_owner_id=image_owner_id)
        mock_log_cfg.return_value = 'FAKE CFG'

        createcompute = compute_tasks.ComputeCreate()

        mock_driver.build.return_value = COMPUTE_ID
        # Test execute()
        compute_id = createcompute.execute(_amphora_mock.id,
                                           ports=[_port],
                                           server_group_id=SERVER_GRPOUP_ID)

        # Validate that the build method was called properly
        mock_driver.build.assert_called_once_with(
            name="amphora-" + _amphora_mock.id,
            amphora_flavor=AMP_FLAVOR_ID,
            image_id=AMP_IMAGE_ID,
            image_tag=AMP_IMAGE_TAG,
            image_owner=image_owner_id,
            key_name=AMP_SSH_KEY_NAME,
            sec_groups=AMP_SEC_GROUPS,
            network_ids=AMP_NET,
            port_ids=[PORT_ID],
            config_drive_files={
                '/etc/octavia/'
                'amphora-agent.conf': 'test_conf',
                '/etc/rsyslog.d/10-rsyslog.conf': 'FAKE CFG'
            },
            user_data=None,
            server_group_id=SERVER_GRPOUP_ID)

        # Make sure it returns the expected compute_id
        self.assertEqual(COMPUTE_ID, compute_id)

        # Test that a build exception is raised
        createcompute = compute_tasks.ComputeCreate()

        self.assertRaises(TypeError,
                          createcompute.execute,
                          _amphora_mock,
                          config_drive_files='test_cert')

        # Test revert()

        _amphora_mock.compute_id = COMPUTE_ID

        createcompute = compute_tasks.ComputeCreate()
        createcompute.revert(compute_id, _amphora_mock.id)

        # Validate that the delete method was called properly
        mock_driver.delete.assert_called_once_with(COMPUTE_ID)

        # Test that a delete exception is not raised

        createcompute.revert(COMPUTE_ID, _amphora_mock.id)
Beispiel #4
0
    def test_compute_create_user_data(self, mock_driver, mock_ud_conf,
                                      mock_conf, mock_jinja):

        self.conf.config(group="controller_worker",
                         user_data_config_drive=True)
        mock_ud_conf.return_value = 'test_ud_conf'
        createcompute = compute_tasks.ComputeCreate()

        mock_driver.build.return_value = COMPUTE_ID
        # Test execute()
        compute_id = createcompute.execute(_db_amphora_mock.id,
                                           ports=[_port],
                                           server_group_id=None)

        # Validate that the build method was called properly
        mock_driver.build.assert_called_once_with(name="amphora-" +
                                                  _db_amphora_mock.id,
                                                  amphora_flavor=AMP_FLAVOR_ID,
                                                  image_tag=AMP_IMAGE_TAG,
                                                  image_owner='',
                                                  key_name=AMP_SSH_KEY_NAME,
                                                  sec_groups=AMP_SEC_GROUPS,
                                                  network_ids=AMP_NET,
                                                  port_ids=[PORT_ID],
                                                  config_drive_files=None,
                                                  user_data='test_ud_conf',
                                                  server_group_id=None,
                                                  availability_zone=None)

        # Make sure it returns the expected compute_id
        self.assertEqual(COMPUTE_ID, compute_id)

        # Test that a build exception is raised
        createcompute = compute_tasks.ComputeCreate()

        self.assertRaises(TypeError,
                          createcompute.execute,
                          _db_amphora_mock,
                          config_drive_files='test_cert')

        # Test revert()

        _db_amphora_mock.compute_id = COMPUTE_ID

        createcompute = compute_tasks.ComputeCreate()
        createcompute.revert(compute_id, _db_amphora_mock.id)

        # Validate that the delete method was called properly
        mock_driver.delete.assert_called_once_with(COMPUTE_ID)

        # Test that a delete exception is not raised

        createcompute.revert(COMPUTE_ID, _db_amphora_mock.id)
Beispiel #5
0
    def get_create_amphora_flow(self):
        """Creates a flow to create an amphora.

        :returns: The flow for creating the amphora
        """
        create_amphora_flow = linear_flow.Flow(constants.CREATE_AMPHORA_FLOW)
        create_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        create_amphora_flow.add(
            lifecycle_tasks.AmphoraIDToErrorOnRevertTask(
                requires=constants.AMPHORA_ID))
        if (CONF.controller_worker.amphora_driver ==
                'amphora_haproxy_rest_driver'):
            create_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))

            create_amphora_flow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            create_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM,
                              constants.BUILD_TYPE_PRIORITY, constants.FLAVOR),
                    provides=constants.COMPUTE_ID))
        else:
            create_amphora_flow.add(
                compute_tasks.ComputeCreate(
                    requires=(constants.AMPHORA_ID,
                              constants.BUILD_TYPE_PRIORITY, constants.FLAVOR),
                    provides=constants.COMPUTE_ID))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amphora_flow.add(
            compute_tasks.ComputeActiveWait(requires=(constants.COMPUTE_ID,
                                                      constants.AMPHORA_ID),
                                            provides=constants.COMPUTE_OBJ))
        create_amphora_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        retry_subflow = linear_flow.Flow(
            constants.CREATE_AMPHORA_RETRY_SUBFLOW,
            retry=amphora_driver_tasks.AmpRetry())
        retry_subflow.add(
            amphora_driver_tasks.AmphoraComputeConnectivityWait(
                requires=constants.AMPHORA,
                inject={'raise_retry_exception': True}))
        create_amphora_flow.add(retry_subflow)
        create_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA,
                                         provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraReadyInDB(requires=constants.AMPHORA))

        return create_amphora_flow
Beispiel #6
0
    def get_create_amphora_flow(self):
        """Creates a flow to create an amphora.

        :returns: The flow for creating the amphora
        """
        create_amphora_flow = linear_flow.Flow(constants.CREATE_AMPHORA_FLOW)
        create_amphora_flow.add(
            database_tasks.CreateAmphoraInDB(provides=constants.AMPHORA_ID))
        create_amphora_flow.add(
            lifecycle_tasks.AmphoraIDToErrorOnRevertTask(
                requires=constants.AMPHORA_ID))
        if self.REST_AMPHORA_DRIVER:
            create_amphora_flow.add(
                cert_task.GenerateServerPEMTask(provides=constants.SERVER_PEM))

            create_amphora_flow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            create_amphora_flow.add(
                compute_tasks.CertComputeCreate(
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM,
                              constants.BUILD_TYPE_PRIORITY, constants.FLAVOR),
                    provides=constants.COMPUTE_ID))
        else:
            create_amphora_flow.add(
                compute_tasks.ComputeCreate(
                    requires=(constants.AMPHORA_ID,
                              constants.BUILD_TYPE_PRIORITY, constants.FLAVOR),
                    provides=constants.COMPUTE_ID))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraBootingInDB(
                requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amphora_flow.add(
            compute_tasks.ComputeActiveWait(requires=(constants.COMPUTE_ID,
                                                      constants.AMPHORA_ID),
                                            provides=constants.COMPUTE_OBJ))
        create_amphora_flow.add(
            database_tasks.UpdateAmphoraInfo(requires=(constants.AMPHORA_ID,
                                                       constants.COMPUTE_OBJ),
                                             provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraComputeConnectivityWait(
                requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.ReloadAmphora(requires=constants.AMPHORA_ID,
                                         provides=constants.AMPHORA))
        create_amphora_flow.add(
            amphora_driver_tasks.AmphoraFinalize(requires=constants.AMPHORA))
        create_amphora_flow.add(
            database_tasks.MarkAmphoraReadyInDB(requires=constants.AMPHORA))

        return create_amphora_flow
Beispiel #7
0
    def _get_create_amp_for_lb_subflow(self, prefix, role):
        """Create a new amphora for lb."""

        sf_name = prefix + '-' + constants.CREATE_AMP_FOR_LB_SUBFLOW
        create_amp_for_lb_subflow = linear_flow.Flow(sf_name)
        create_amp_for_lb_subflow.add(database_tasks.CreateAmphoraInDB(
            name=sf_name + '-' + constants.CREATE_AMPHORA_INDB,
            requires=constants.LOADBALANCER_ID,
            provides=constants.AMPHORA_ID))

        require_server_group_id_condition = (
            role in (constants.ROLE_BACKUP, constants.ROLE_MASTER) and
            CONF.nova.enable_anti_affinity)

        if (CONF.controller_worker.amphora_driver ==
                'amphora_haproxy_rest_driver'):
            create_amp_for_lb_subflow.add(cert_task.GenerateServerPEMTask(
                name=sf_name + '-' + constants.GENERATE_SERVER_PEM,
                provides=constants.SERVER_PEM))

            create_amp_for_lb_subflow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    name=sf_name + '-' + constants.UPDATE_CERT_EXPIRATION,
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            if require_server_group_id_condition:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.SERVER_PEM,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.SERVER_GROUP_ID,
                        constants.FLAVOR,
                        constants.AVAILABILITY_ZONE,
                    ),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.SERVER_PEM,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.FLAVOR,
                        constants.AVAILABILITY_ZONE,
                    ),
                    provides=constants.COMPUTE_ID))
        else:
            if require_server_group_id_condition:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.SERVER_GROUP_ID,
                        constants.FLAVOR,
                        constants.AVAILABILITY_ZONE,
                    ),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.FLAVOR,
                        constants.AVAILABILITY_ZONE,
                    ),
                    provides=constants.COMPUTE_ID))

        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraComputeId(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraBootingInDB(
            name=sf_name + '-' + constants.MARK_AMPHORA_BOOTING_INDB,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(compute_tasks.ComputeActiveWait(
            name=sf_name + '-' + constants.COMPUTE_WAIT,
            requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
            provides=constants.COMPUTE_OBJ))
        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraInfo(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
            provides=constants.AMPHORA))

        return create_amp_for_lb_subflow
Beispiel #8
0
    def _get_create_amp_for_lb_subflow(self, prefix, role):
        """Create a new amphora for lb."""

        sf_name = prefix + '-' + constants.CREATE_AMP_FOR_LB_SUBFLOW
        create_amp_for_lb_subflow = linear_flow.Flow(sf_name)
        create_amp_for_lb_subflow.add(database_tasks.CreateAmphoraInDB(
            name=sf_name + '-' + constants.CREATE_AMPHORA_INDB,
            provides=constants.AMPHORA_ID))

        require_server_group_id_condition = (
            role in (constants.ROLE_BACKUP, constants.ROLE_MASTER) and
            CONF.nova.enable_anti_affinity)

        if self.REST_AMPHORA_DRIVER:
            create_amp_for_lb_subflow.add(cert_task.GenerateServerPEMTask(
                name=sf_name + '-' + constants.GENERATE_SERVER_PEM,
                provides=constants.SERVER_PEM))

            create_amp_for_lb_subflow.add(
                database_tasks.UpdateAmphoraDBCertExpiration(
                    name=sf_name + '-' + constants.UPDATE_CERT_EXPIRATION,
                    requires=(constants.AMPHORA_ID, constants.SERVER_PEM)))

            if require_server_group_id_condition:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.SERVER_PEM,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.SERVER_GROUP_ID,
                        constants.FLAVOR
                    ),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.CertComputeCreate(
                    name=sf_name + '-' + constants.CERT_COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.SERVER_PEM,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.FLAVOR
                    ),
                    provides=constants.COMPUTE_ID))
        else:
            if require_server_group_id_condition:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.SERVER_GROUP_ID,
                        constants.FLAVOR
                    ),
                    provides=constants.COMPUTE_ID))
            else:
                create_amp_for_lb_subflow.add(compute_tasks.ComputeCreate(
                    name=sf_name + '-' + constants.COMPUTE_CREATE,
                    requires=(
                        constants.AMPHORA_ID,
                        constants.BUILD_TYPE_PRIORITY,
                        constants.FLAVOR
                    ),
                    provides=constants.COMPUTE_ID))

        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraComputeId(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_COMPUTEID,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraBootingInDB(
            name=sf_name + '-' + constants.MARK_AMPHORA_BOOTING_INDB,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_ID)))
        create_amp_for_lb_subflow.add(compute_tasks.ComputeActiveWait(
            name=sf_name + '-' + constants.COMPUTE_WAIT,
            requires=(constants.COMPUTE_ID, constants.AMPHORA_ID),
            provides=constants.COMPUTE_OBJ))
        create_amp_for_lb_subflow.add(database_tasks.UpdateAmphoraInfo(
            name=sf_name + '-' + constants.UPDATE_AMPHORA_INFO,
            requires=(constants.AMPHORA_ID, constants.COMPUTE_OBJ),
            provides=constants.AMPHORA))
        create_amp_for_lb_subflow.add(
            amphora_driver_tasks.AmphoraComputeConnectivityWait(
                name=sf_name + '-' + constants.AMP_COMPUTE_CONNECTIVITY_WAIT,
                requires=constants.AMPHORA))
        create_amp_for_lb_subflow.add(amphora_driver_tasks.AmphoraFinalize(
            name=sf_name + '-' + constants.AMPHORA_FINALIZE,
            requires=constants.AMPHORA))
        create_amp_for_lb_subflow.add(
            database_tasks.MarkAmphoraAllocatedInDB(
                name=sf_name + '-' + constants.MARK_AMPHORA_ALLOCATED_INDB,
                requires=(constants.AMPHORA, constants.LOADBALANCER_ID)))
        create_amp_for_lb_subflow.add(database_tasks.ReloadAmphora(
            name=sf_name + '-' + constants.RELOAD_AMPHORA,
            requires=constants.AMPHORA_ID,
            provides=constants.AMPHORA))

        if role == constants.ROLE_MASTER:
            create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraMasterInDB(
                name=sf_name + '-' + constants.MARK_AMP_MASTER_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_BACKUP:
            create_amp_for_lb_subflow.add(database_tasks.MarkAmphoraBackupInDB(
                name=sf_name + '-' + constants.MARK_AMP_BACKUP_INDB,
                requires=constants.AMPHORA))
        elif role == constants.ROLE_STANDALONE:
            create_amp_for_lb_subflow.add(
                database_tasks.MarkAmphoraStandAloneInDB(
                    name=sf_name + '-' + constants.MARK_AMP_STANDALONE_INDB,
                    requires=constants.AMPHORA))

        return create_amp_for_lb_subflow