コード例 #1
0
    def test_make_eb_dir(self):
        self.create_config_file()

        with patch('os.makedirs') as makedirs_mock:
            fileoperations.make_eb_dir('saved_configs')

            makedirs_mock.assert_called_once_with(
                os.path.join('.elasticbeanstalk', 'saved_configs'))
コード例 #2
0
    def test_make_eb_dir__directory_already_exists(self):
        self.create_config_file()
        os.mkdir(os.path.join('.elasticbeanstalk', 'saved_configs'))

        with patch('os.makedirs') as makedirs_mock:
            fileoperations.make_eb_dir('saved_configs')

            makedirs_mock.assert_not_called()
コード例 #3
0
    def test_resolve_config_location_private(self):
        cfg_name = 'myfile'
        location = 'saved_configs' + os.path.sep + cfg_name + '.cfg.yml'
        fileoperations.make_eb_dir('saved_configs')
        fileoperations.write_to_eb_data_file(location, self.data)

        location = os.path.expanduser(os.getcwd() + os.path.sep +
                                      fileoperations.beanstalk_directory +
                                      location)

        result = saved_configs.resolve_config_location(cfg_name)
        self.assertEqual(result, location)
コード例 #4
0
    def test_update_config_resolve_normal(self, mock_upload):
        cfg_name = 'myfile.cfg.yml'
        location = 'saved_configs' + os.path.sep + cfg_name
        fileoperations.make_eb_dir('saved_configs')
        fileoperations.write_to_eb_data_file(location, self.data)

        location = os.getcwd() + os.path.sep + \
                   fileoperations.beanstalk_directory + location

        saved_configs.update_config('app', 'myfile')

        mock_upload.assert_called_with('app', 'myfile', location)
コード例 #5
0
    def test_resolve_config_location_correct_resolve_with_extension(self):
        cfg_name = 'myfile.cfg.yml'
        location_public = cfg_name
        location_private = 'saved_configs' + os.path.sep + cfg_name
        fileoperations.make_eb_dir('saved_configs')
        fileoperations.write_to_eb_data_file(location_public, self.data)
        fileoperations.write_to_eb_data_file(location_private, self.data)

        location_public = os.getcwd() + os.path.sep + \
            fileoperations.beanstalk_directory + location_public
        location_private = os.getcwd() + os.path.sep + \
            fileoperations.beanstalk_directory + location_private

        result = saved_configs.resolve_config_location(cfg_name)
        self.assertEqual(result, location_private)
コード例 #6
0
def download_source_bundle(app_name, env_name):
    env = elasticbeanstalk.get_environment(app_name=app_name,
                                           env_name=env_name)
    if env.version_label and env.version_label != 'Sample Application':
        app_version = elasticbeanstalk.get_application_versions(
            app_name,
            version_labels=[env.version_label])['ApplicationVersions'][0]

        source_bundle = app_version['SourceBundle']
        bucket_name = source_bundle['S3Bucket']
        key_name = source_bundle['S3Key']
        io.echo('Downloading application version...')
        data = s3.get_object(bucket_name, key_name)
        filename = get_filename(key_name)
    else:
        # sample app
        template = cloudformation.get_template('awseb-' + env.id + '-stack')
        try:
            url = template['TemplateBody']['Parameters']['AppSource'][
                'Default']
        except KeyError:
            raise NotFoundError('Can not find app source for environment')
        utils.get_data_from_url(url)
        io.echo('Downloading application version...')
        data = utils.get_data_from_url(url, timeout=30)
        filename = 'sample.zip'

    fileoperations.make_eb_dir('downloads/')
    location = fileoperations.get_eb_file_full_location('downloads/' +
                                                        filename)
    fileoperations.write_to_data_file(location, data)
    io.echo('Application version downloaded to:', location)

    cwd = os.getcwd()
    try:
        fileoperations._traverse_to_project_root()
        if heuristics.directory_is_empty():
            # If we dont have any project code, unzip as current project
            io.echo('Unzipping application version as project files.')
            fileoperations.unzip_folder(location, os.getcwd())
            io.echo('Done.')
    finally:
        os.chdir(cwd)
コード例 #7
0
def write_to_local_config(cfg_name, data):
    fileoperations.make_eb_dir(SAVED_CONFIG_FOLDER_NAME)

    file_location = SAVED_CONFIG_FOLDER_NAME + cfg_name + '.cfg.yml'
    fileoperations.write_to_eb_data_file(file_location, data)
    return fileoperations.get_eb_file_full_location(file_location)
コード例 #8
0
def write_to_local_config(cfg_name, data):
    fileoperations.make_eb_dir(SAVED_CONFIG_FOLDER_NAME)

    file_location = SAVED_CONFIG_FOLDER_NAME + cfg_name + '.cfg.yml'
    fileoperations.write_to_eb_data_file(file_location, data)
    return fileoperations.get_eb_file_full_location(file_location)