def test_can_backup_rsr_database(self):
        """fab.tests.tasks.database.backup_rsr_database_test  Can backup the RSR database"""

        self.mock_database_host.backup_rsr_database()
        self.mox.ReplayAll()

        self.backup_rsr_database_task.run(HostControllerMode.REMOTE, HostConfigSpecification().create_preconfigured_with(HostAlias.TEST))
    def test_can_create_preconfigured_host_config_specification(self):
        """fab.tests.config.spec.host_config_specification_test  Can create a preconfigured host configuration specification"""

        self.assertEqual(
            self._expected_spec(ConfigType.PRECONFIGURED, [HostAlias.TEST]),
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
    def test_can_create_custom_host_config_specification(self):
        """fab.tests.config.spec.host_config_specification_test  Can create a custom host configuration specification"""

        self.assertEqual(
            self._expected_spec(ConfigType.CUSTOM,
                                ['/path/to/custom_host_config_module.py']),
            HostConfigSpecification().create_custom_with(
                '/path/to/custom_host_config_module.py'))
    def test_can_create_standard_host_config_specification(self):
        """fab.tests.config.spec.host_config_specification_test  Can create a standard host configuration specification"""

        self.assertEqual(
            self._expected_spec(
                ConfigType.STANDARD,
                [HostAlias.UAT, RepositoryBranch.DEVELOP, 'some_rsr_db']),
            HostConfigSpecification().create_standard_with(
                HostAlias.UAT, RepositoryBranch.DEVELOP, 'some_rsr_db'))
Esempio n. 5
0
    def test_can_run_new_database_migrations(self):
        """fab.tests.tasks.database.run_new_database_migrations_test  Can run new database migrations"""

        self.mock_database_host.run_new_migrations()
        self.mox.ReplayAll()

        self.run_database_migrations_task.run(
            HostControllerMode.REMOTE,
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
    def test_can_configure_linux_host_with_given_host_config_specification(
            self):
        """fab.tests.tasks.environment.linux_host_base_task_test  Can configure Linux host with the given host configuration specification"""

        host_config_spec = HostConfigSpecification().create_preconfigured_with(
            HostAlias.TEST)

        self.mock_config_loader.parse(host_config_spec).AndReturn(
            CIDeploymentHostConfig.for_test())
        self.mox.ReplayAll()

        self.assertIsInstance(
            self.linux_host_base_task._configure_linux_host_with(
                host_config_spec), LinuxHost)
Esempio n. 7
0
    def test_can_deploy_rsr_app(self):
        """fab.tests.tasks.app.deploy_rsr_app_test  Can deploy RSR app"""

        self.mock_feedback.comment('Starting RSR app deployment')
        self.mock_app_deployer.ensure_user_has_required_deployment_permissions(
        )
        self.mock_app_deployer.ensure_required_directories_exist()
        self.mock_app_deployer.clean_deployment_directories()
        self.mock_app_deployer.download_and_unpack_rsr_archive()
        self.mock_app_deployer.ensure_app_symlinks_exist()
        self.mox.ReplayAll()

        self.deploy_rsr_app_task.run(
            HostControllerMode.REMOTE,
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
Esempio n. 8
0
    def test_can_update_system_python_packages(self):
        """fab.tests.tasks.environment.python.update_system_python_packages_test  Can update system python packages"""

        mock_linux_host = self.mox.CreateMock(LinuxHost)

        update_system_python_packages_task = StubbedUpdateSystemPythonPackages(
            mock_linux_host)

        mock_linux_host.ensure_user_has_required_deployment_permissions(
            User.CURRENT)
        mock_linux_host.update_system_python_packages()
        self.mox.ReplayAll()

        update_system_python_packages_task.run(
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
Esempio n. 9
0
    def test_can_verify_expected_system_package_dependencies(self):
        """fab.tests.tasks.environment.linux.verify_system_packages_test  Can verify expected system package dependencies"""

        self.mock_linux_host.ensure_user_has_required_deployment_permissions(
            User.CURRENT)
        self.mock_linux_host.update_system_package_sources()

        for package_specifications in SystemPackageSpecifications.ALL_PACKAGES:
            self.mock_linux_host.exit_if_system_package_dependencies_not_met(
                package_specifications)

        self.mox.ReplayAll()

        self.verify_system_packages_task.run(
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
Esempio n. 10
0
    def test_can_install_specified_python_version(self):
        """fab.tests.tasks.environment.python.install_python_test  Can install specified python version"""

        mock_linux_host = self.mox.CreateMock(LinuxHost)

        install_python_task = StubbedInstallPython(mock_linux_host)

        mock_linux_host.ensure_user_has_required_deployment_permissions(
            User.CURRENT)
        mock_linux_host.ensure_python_is_installed_with_version('2.7.2')
        self.mox.ReplayAll()

        install_python_task.run(
            '2.7.2',
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
Esempio n. 11
0
    def test_can_run_remote_deployment_task(self):
        """fab.tests.tasks.task_runner_test  Can run remote deployment task"""

        host_config_spec = HostConfigSpecification().create_preconfigured_with(
            HostAlias.TEST)
        expected_parameter_list = TaskParameters().compose_from(
            host_config_spec, [TaskParameters.REMOTE_HOST_CONTROLLER_MODE])

        self._load_host_config_from(host_config_spec)
        self.mock_process_runner.execute(
            self._expected_fabric_call_with(
                BackupRSRDatabase, expected_parameter_list,
                self.deployment_host_config.ssh_connection))
        self.mox.ReplayAll()

        self.task_runner.run_remote_deployment_task(BackupRSRDatabase,
                                                    host_config_spec)
Esempio n. 12
0
    def test_can_run_deployment_task_with_additional_custom_parameters(self):
        """fab.tests.tasks.task_runner_test  Can run deployment task with additional custom parameters"""

        host_config_spec = HostConfigSpecification().create_preconfigured_with(
            HostAlias.TEST)
        expected_parameter_list = TaskParameters().compose_from(
            host_config_spec, ['python_version=some_version'])

        self._load_host_config_from(host_config_spec)
        self.mock_process_runner.execute(
            self._expected_fabric_call_with(
                InstallPython, expected_parameter_list,
                self.deployment_host_config.ssh_connection))
        self.mox.ReplayAll()

        self.task_runner.run_deployment_task(InstallPython, host_config_spec,
                                             ['python_version=some_version'])
Esempio n. 13
0
    def test_can_run_deployment_task(self):
        """fab.tests.tasks.task_runner_test  Can run deployment task"""

        host_config_spec = HostConfigSpecification().create_preconfigured_with(
            HostAlias.TEST)
        expected_parameter_list = TaskParameters().compose_from(
            host_config_spec)

        self._load_host_config_from(host_config_spec)
        self.mock_process_runner.execute(
            self._expected_fabric_call_with(
                UpdateSystemPythonPackages, expected_parameter_list,
                self.deployment_host_config.ssh_connection))
        self.mox.ReplayAll()

        self.task_runner.run_deployment_task(UpdateSystemPythonPackages,
                                             host_config_spec)
Esempio n. 14
0
    def test_can_rebuild_rsr_virtualenv(self):
        """fab.tests.tasks.environment.python.virtualenv.rebuild_rsr_env_test  Can rebuild an RSR virtualenv"""

        self.mock_virtualenv_deployment_host.ensure_user_has_required_deployment_permissions(
        )
        self.mock_virtualenv_deployment_host.ensure_virtualenv_exists()
        self.mock_virtualenv_deployment_host.remove_previously_downloaded_package_sources(
        )
        self.mock_virtualenv_deployment_host.set_web_group_permissions_and_ownership_on_deployed_virtualenv(
        )
        self.mock_virtualenv_deployment_host.install_virtualenv_packages(
            self.virtualenv_installer_config.rsr_requirements_url)
        self.mock_virtualenv_deployment_host.set_web_group_permissions_and_ownership_on_deployed_virtualenv(
        )
        self.mock_virtualenv_deployment_host.ensure_virtualenv_symlinks_exist()
        self.mox.ReplayAll()

        self.rebuild_virtualenv_task.run(
            HostControllerMode.REMOTE,
            HostConfigSpecification().create_preconfigured_with(
                HostAlias.TEST))
Esempio n. 15
0
    def test_will_raise_not_implemented_error_if_no_database_actions_defined(
            self):
        """fab.tests.tasks.database.rsr_database_task_test  Will raise NotImplementedError if no database actions have been defined"""

        mock_config_loader = self.mox.CreateMock(DeploymentConfigLoader)
        mock_database_host = self.mox.CreateMock(DatabaseHost)
        host_config_spec = HostConfigSpecification().create_preconfigured_with(
            HostAlias.TEST)

        mock_config_loader.parse(host_config_spec).AndReturn(
            CIDeploymentHostConfig.for_test())
        self.mox.ReplayAll()

        database_task = StubbedRSRDatabaseTask(mock_config_loader,
                                               mock_database_host)

        with self.assertRaises(NotImplementedError) as raised:
            database_task.run(HostControllerMode.REMOTE, host_config_spec)

        self.assertEqual('No database actions defined',
                         raised.exception.message)
def display_usage_and_exit_if_release_parameters_are_missing():
    if len(sys.argv) < 4:
        print '>> Some missing parameters'
        print 'Usage: %s <host_alias> <repository_branch> <rsr_database_name>' % os.path.basename(__file__)
        print '       where the host alias is either: test, test2 or uat\n'
        sys.exit(1)

def exit_if_attempting_deployment_to_live_server(host_alias):
    if host_alias == 'live':
        print '>> Deployment of release candidate to live server (www.akvo.org) is not permitted\n'
        sys.exit(1)

def deploy_rsr_release_candidate(scenario_runner, release_config_spec):
    update_host_system_and_deploy_rsr(scenario_runner, release_config_spec)
    scenario_runner.run_step('5_fetch_rsr_data')
    rebuild_rsr_database_and_run_new_migrations(scenario_runner, release_config_spec)


if __name__ == '__main__':
    display_usage_and_exit_if_release_parameters_are_missing()

    host_alias = sys.argv[1]
    repository_branch = sys.argv[2]
    rsr_database_name = sys.argv[3]

    exit_if_attempting_deployment_to_live_server(host_alias)

    release_config_spec = HostConfigSpecification().create_standard_with(host_alias, repository_branch, rsr_database_name)

    deploy_rsr_release_candidate(execution.scenarios.runner.ScenarioRunner(), release_config_spec)