def test_tosca_based_shell_packed(self):
        # Arrange
        self.fs.CreateFile('nut-shell/TOSCA-Metadata/TOSCA.meta',
                           contents='TOSCA-Meta-File-Version: 1.0 \n'
                           'CSAR-Version: 1.1 \n'
                           'Created-By: Anonymous\n'
                           'Entry-Definitions: shell-definition.yml')

        self.fs.CreateFile(
            'nut-shell/shell-definition.yml',
            contents='tosca_definitions_version: tosca_simple_yaml_1_0\n'
            'metadata:\n'
            '  template_name: NutShell\n'
            '  template_author: Anonymous\n'
            '  template_version: 1.0.0\n'
            'node_types:\n'
            '  vendor.switch.NXOS:\n'
            '    derived_from: cloudshell.nodes.Switch\n'
            '    artifacts:\n'
            '      icon:\n'
            '        file: nxos.png\n'
            '        type: tosca.artifacts.File\n'
            '      driver:\n'
            '        file: NutShellDriver.zip\n'
            '        type: tosca.artifacts.File')

        self.fs.CreateFile('nut-shell/nxos.png', contents='IMAGE')

        self.fs.CreateFile('nut-shell/src/driver.py',
                           contents='DRIVER CONTENT')

        os.chdir('nut-shell')

        shell_package_builder = ShellPackageBuilder()

        # Act
        with patch('click.echo'):
            shell_package_builder.pack('/nut-shell')

        # Assert
        assertFileExists(self, 'dist/NutShell.zip')
        TestPackageBuilder.unzip('dist/NutShell.zip', 'dist/package_content')

        assertFileExists(self,
                         'dist/package_content/TOSCA-Metadata/TOSCA.meta')
        assertFileExists(self, 'dist/package_content/shell-definition.yml')
        assertFileExists(self, 'dist/package_content/nxos.png')
        assertFileExists(self, 'dist/package_content/NutShellDriver.zip')
Exemplo n.º 2
0
    def test_driver_generated_successfully(self):
        self.fs.CreateFile("nut-shell/dist/NutShell.zip", contents="ZIP")

        self.fs.CreateFile("nut-shell/temp/data_model.py",
                           contents="python data model content")

        ArchiveCreator.make_archive("nut-shell/temp/data-model", "zip",
                                    "nut-shell/temp")

        driver_generator = DriverGenerator()
        config = InstallConfig("TEST-HOST", 9000, "user", "pwd", "Global",
                               "author", "online_mode", "template_location",
                               "github_login", "github_password")

        with patch(
                "shellfoundry.utilities.driver_generator.PackagingRestApiClient"
        ) as mock_rest:
            rest_client_mock = Mock()
            rest_client_mock.token = "TEST-TOKEN"
            mock_rest.return_value = rest_client_mock

            with patch("shellfoundry.utilities.driver_generator.post"
                       ) as post_mock:

                with open("nut-shell/temp/data-model.zip",
                          "r") as data_model_file:
                    file_content = data_model_file.read()

                response = Mock()
                response.status_code = 200
                response.content = file_content
                post_mock.return_value = response

                # Act
                driver_generator.generate_driver(
                    cloudshell_config=config,
                    destination_path="nut-shell/src",
                    package_full_path="nut-shell/dist/NutShell.zip",
                    shell_filename="NutShell.zip",
                    shell_name="NutShell")

        # Assert
        assertFileExists(self, "nut-shell/src/data_model.py")
Exemplo n.º 3
0
    def test_driver_generated_successfully(self):
        self.fs.CreateFile('nut-shell/dist/NutShell.zip', contents='ZIP')

        self.fs.CreateFile('nut-shell/temp/data_model.py',
                           contents='python data model content')

        ArchiveCreator.make_archive('nut-shell/temp/data-model', 'zip',
                                    'nut-shell/temp')

        driver_generator = DriverGenerator()
        config = InstallConfig('TEST-HOST', 9000, 'user', 'pwd', 'Global')

        with patch(
                'shellfoundry.utilities.driver_generator.PackagingRestApiClient'
        ) as mock_rest:
            rest_client_mock = Mock()
            rest_client_mock.token = 'TEST-TOKEN'
            mock_rest.return_value = rest_client_mock

            with patch('shellfoundry.utilities.driver_generator.post'
                       ) as post_mock:

                with open('nut-shell/temp/data-model.zip',
                          'r') as data_model_file:
                    file_content = data_model_file.read()

                response = Mock()
                response.status_code = 200
                response.content = file_content
                post_mock.return_value = response

                # Act
                driver_generator.generate_driver(
                    cloudshell_config=config,
                    destination_path='nut-shell/src',
                    package_full_path='nut-shell/dist/NutShell.zip',
                    shell_filename='NutShell.zip',
                    shell_name='NutShell')

        # Assert
        assertFileExists(self, 'nut-shell/src/data_model.py')