Ejemplo n.º 1
0
    def test_pack_succeeds_when_shellconfig_is_missing(self):
        # Arrange
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/datamodel.xml',
            contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py',
                           contents='')
        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws',
                                  'AwsDriver')

        # Assert
        assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip',
                                 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/metadata.xml')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
        assertFileExists(
            self,
            'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip'
        )
Ejemplo n.º 2
0
    def test_it_ignores_other_nonimage_files_in_the_datamodel_dir(self):
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/datamodel.xml',
            contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/shellconfig.xml',
            contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py',
                           contents='')

        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/iamimage.blah',
            contents='')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws',
                                  'AwsDriver')

        # Assert
        assertFileDoesNotExist(
            self, 'aws/amazon_web_services/package/DataModel/iamimage.blah')
Ejemplo n.º 3
0
    def test_it_does_not_merge_datamodel_if_shell_config_does_not_exist(self):
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/metadata.xml', contents='')

        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/datamodel.xml',
            contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/shellconfig.xml',
            contents='')

        os.chdir('work')
        builder = PackageBuilder()

        with patch(
                'shellfoundry.utilities.package_builder.ShellDataModelMerger'
        ) as MockClass:
            # Act
            instance = MockClass.return_value
            instance.merge_shell_model.return_value = 'Test'
            with patch('click.echo'):
                builder.build_package('aws/amazon_web_services', 'aws',
                                      'AwsDriver')
            instance.merge_shell_model.assert_not_called()

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip',
                                 'aws/amazon_web_services/package')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')

        self._assert_utf_file_content(
            'aws/amazon_web_services/package/DataModel/datamodel.xml', '')
Ejemplo n.º 4
0
class PackCommandExecutor(object):
    def __init__(self):
        self.config_reader = ShellConfigReader()
        self.package_builder = PackageBuilder()
        self.shell_package_builder = ShellPackageBuilder()

    def pack(self):

        current_path = os.getcwd()

        shell_package = ShellPackage(current_path)
        if shell_package.is_layer_one():
            click.secho(
                "Packaging a L1 shell directly via shellfoundry is not supported.",
                fg="yellow")
        elif shell_package.is_tosca():
            self.shell_package_builder.pack(current_path)
        else:
            self._pack_old_school_shell(current_path)

    def _pack_old_school_shell(self, current_path):
        try:
            config = self.config_reader.read()
            self.package_builder.build_package(current_path, config.name,
                                               config.driver_name)
        except ShellYmlMissingException:
            click.echo('shell.yml file is missing')
        except WrongShellYmlException:
            click.echo('shell.yml format is wrong')
    def test_it_replaces_wildcard_according_to_versioning_policy(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/drivermetadata.xml',
                           contents='<Driver Description="CloudShell shell" '
                                    'MainClass="driver.ImplementingDiscoveryDriver" '
                                    'Name="ImplementingDiscoveryDriver" Version="1.2.*">'
                                    '</Driver>')

        os.chdir('work')
        driver_version_strategy = Mock()
        driver_version_strategy.supports_version_pattern.return_value = True
        driver_version_strategy.get_version.return_value = '1.2.3.4'
        builder = PackageBuilder(driver_version_strategy)

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip',
                                 'aws/driver')
        assertFileExists(self, 'aws/driver/drivermetadata.xml')

        # packed file should have a dynamic version
        self._assert_driver_version_equals('aws/driver/drivermetadata.xml', '1.2.3.4')
        # original file should still have the original value
        self._assert_driver_version_equals('aws/amazon_web_services/src/drivermetadata.xml', '1.2.*')
    def test_build_package_package_created(self):
        # Arrange
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/datamodel.xml',
            contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/shellconfig.xml',
            contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py',
                           contents='')
        os.chdir('work')
        builder = PackageBuilder()

        # Act
        builder.build_package('aws/amazon_web_services', 'aws')

        # Assert
        assertFileExists(
            self, 'aws/amazon_web_services/package/datamodel/datamodel.xml')
        assertFileExists(
            self,
            'aws/amazon_web_services/package/Configuration/shellconfig.xml')
        assertFileExists(
            self,
            'aws/amazon_web_services/package/Resource Drivers - Python/aws Driver.zip'
        )
        assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
Ejemplo n.º 7
0
    def test_it_updates_the_driver_version_dynamically(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/drivermetadata.xml',
                           contents='<Driver Description="CloudShell shell" '
                                    'MainClass="driver.ImplementingDiscoveryDriver" '
                                    'Name="ImplementingDiscoveryDriver" Version="1.2.*">'
                                    '</Driver>')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip',
                                 'aws/driver')
        assertFileExists(self, 'aws/driver/drivermetadata.xml')

        # packed file should have a dynamic version
        self.asset_driver_version('aws/driver/drivermetadata.xml',
                                   '1.2.*', True)

        # original file should still have the original value
        self.asset_driver_version('work/aws/amazon_web_services/src/drivermetadata.xml',
                                  '1.2.*', False)
    def test_it_uses_the_datetime_stamp_policy_for_wildcard_versioning(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/drivermetadata.xml',
                           contents='<Driver Description="CloudShell shell" '
                                    'MainClass="driver.ImplementingDiscoveryDriver" '
                                    'Name="ImplementingDiscoveryDriver" Version="1.2.*">'
                                    '</Driver>')

        os.chdir('work')

        # Act
        with patch('shellfoundry.utilities.package_builder.DriverVersionTimestampBased') as version_mock:
            strategy_instance = Mock()
            version_mock.return_value = strategy_instance
            strategy_instance.get_version.return_value = '1.2.3000.4000'
            builder = PackageBuilder()
            with patch('click.echo'):
                builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip',
                                 'aws/driver')
        assertFileExists(self, 'aws/driver/drivermetadata.xml')

        # packed file should have a dynamic version
        self._assert_driver_version_equals('aws/driver/drivermetadata.xml', '1.2.3000.4000')
        # original file should still have the original value
        self._assert_driver_version_equals('aws/amazon_web_services/src/drivermetadata.xml', '1.2.*')
    def test_it_does_not_update_the_driver_version_when_not_needed(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/drivermetadata.xml',
                           contents='<Driver Description="CloudShell shell" '
                                    'MainClass="driver.ImplementingDiscoveryDriver" '
                                    'Name="ImplementingDiscoveryDriver" Version="1.2.3">'
                                    '</Driver>')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip',
                                 'aws/driver')
        assertFileExists(self, 'aws/driver/drivermetadata.xml')

        # packed file should not have a timestamped version
        self._assert_driver_version_equals('aws/driver/drivermetadata.xml', '1.2.3')
        # original file should still have the original value
        self._assert_driver_version_equals('aws/amazon_web_services/src/drivermetadata.xml', '1.2.3')
Ejemplo n.º 10
0
class PackCommandExecutor(object):
    def __init__(self):
        self.config_reader = ShellConfigReader()
        self.package_builder = PackageBuilder()
        self.shell_package_builder = ShellPackageBuilder()

    def pack(self):

        current_path = os.getcwd()

        shell_package = ShellPackage(current_path)
        if shell_package.is_tosca():
            self.shell_package_builder.pack(current_path)
        else:
            self._pack_old_school_shell(current_path)

    def _pack_old_school_shell(self, current_path):
        try:
            config = self.config_reader.read()
            self.package_builder.build_package(current_path, config.name,
                                               config.driver_name)
        except ShellYmlMissingException:
            click.echo(u'shell.yml file is missing')
        except WrongShellYmlException:
            click.echo(u'shell.yml format is wrong')
Ejemplo n.º 11
0
class PackCommandExecutor(object):
    def __init__(self):
        self.config_reader = ShellConfigReader()
        self.package_builder = PackageBuilder()

    def pack(self):
        try:
            config = self.config_reader.read()
            current_path = os.getcwd()
            self.package_builder.build_package(current_path, config.name)
        except ShellYmlMissingException:
            click.echo(u'shell.yml file is missing')
        except WrongShellYmlException:
            click.echo(u'shell.yml format is wrong')
Ejemplo n.º 12
0
    def test_it_ignores_other_nonimage_files_in_the_datamodel_dir(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')

        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/iamimage.blah', contents='')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        assertFileDoesNotExist(self, 'aws/amazon_web_services/package/DataModel/iamimage.blah')
Ejemplo n.º 13
0
    def test_pack_succeeds_when_shellconfig_is_missing(self):
        # Arrange
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        os.chdir('work')
        builder = PackageBuilder()

        # Act
        builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/metadata.xml')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
Ejemplo n.º 14
0
class PackCommandExecutor(object):

    def __init__(self):
        self.config_reader = ShellConfigReader()
        self.package_builder = PackageBuilder()
        self.dependencies_packager = PythonDependenciesPackager()

    def pack(self):
        try:
            config = self.config_reader.read()
            current_path = os.getcwd()
            self.package_builder.build_package(current_path, config.name, config.driver_name)
            requirements_path = os.path.join(current_path, 'src', 'requirements.txt')
            dest_path = os.path.join(current_path, 'dist', 'offline_requirements')

            self.dependencies_packager.save_offline_dependencies(requirements_path, dest_path)
        except ShellYmlMissingException:
            click.echo(u'shell.yml file is missing')
        except WrongShellYmlException:
            click.echo(u'shell.yml format is wrong')
Ejemplo n.º 15
0
    def test_it_copies_image_files_in_the_datamodel_dir(self):
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/datamodel.xml',
            contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/shellconfig.xml',
            contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py',
                           contents='')

        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/iamimage.png', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/iamimage.jpg', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/iamimage.gif', contents='')
        self.fs.CreateFile(
            'work/aws/amazon_web_services/datamodel/iamimage.jpeg',
            contents='')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws',
                                  'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip',
                                 'aws/amazon_web_services/package')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/iamimage.png')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/iamimage.jpg')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/iamimage.gif')
        assertFileExists(
            self, 'aws/amazon_web_services/package/DataModel/iamimage.jpeg')
Ejemplo n.º 16
0
    def test_it_does_not_merge_datamodel_if_shell_config_does_not_exist(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')

        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')

        os.chdir('work')
        builder = PackageBuilder()

        with patch('shellfoundry.utilities.package_builder.ShellDataModelMerger') as MockClass:
            # Act
            instance = MockClass.return_value
            instance.merge_shell_model.return_value = 'Test'
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')
            instance.merge_shell_model.assert_not_called()

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')

        self.assert_utf_file_content('aws/amazon_web_services/package/DataModel/datamodel.xml', '')
Ejemplo n.º 17
0
    def test_build_package_package_created(self):
        # Arrange
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')
        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        assertFileExists(self, 'aws/amazon_web_services/dist/aws.zip')
        assertFileDoesNotExist(self, 'aws/amazon_web_services/package')
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/metadata.xml')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/datamodel.xml')
        assertFileExists(self, 'aws/amazon_web_services/package/Configuration/shellconfig.xml')
        assertFileExists(self, 'aws/amazon_web_services/package/Resource Drivers - Python/AwsDriver.zip')
Ejemplo n.º 18
0
    def test_it_copies_image_files_in_the_datamodel_dir(self):
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/metadata.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/datamodel.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/shellconfig.xml', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/src/driver.py', contents='')

        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/iamimage.png', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/iamimage.jpg', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/iamimage.gif', contents='')
        self.fs.CreateFile('work/aws/amazon_web_services/datamodel/iamimage.jpeg', contents='')

        os.chdir('work')
        builder = PackageBuilder()

        # Act
        with patch('click.echo'):
            builder.build_package('aws/amazon_web_services', 'aws', 'AwsDriver')

        # Assert
        TestPackageBuilder.unzip('aws/amazon_web_services/dist/aws.zip', 'aws/amazon_web_services/package')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/iamimage.png')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/iamimage.jpg')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/iamimage.gif')
        assertFileExists(self, 'aws/amazon_web_services/package/DataModel/iamimage.jpeg')
Ejemplo n.º 19
0
 def __init__(self):
     self.config_reader = ShellConfigReader()
     self.package_builder = PackageBuilder()
     self.dependencies_packager = PythonDependenciesPackager()
Ejemplo n.º 20
0
 def __init__(self):
     self.config_reader = ShellConfigReader()
     self.package_builder = PackageBuilder()