def _create_driver(self, package_path, path, driver_name):
     dir_to_zip = os.path.join(path, 'src')
     drivermetadata_path = os.path.join(dir_to_zip, 'drivermetadata.xml')
     version = self._update_driver_version(drivermetadata_path)
     zip_file_path = os.path.join(package_path, 'Resource Drivers - Python', driver_name)
     ArchiveCreator.make_archive(zip_file_path, 'zip', dir_to_zip)
     if version:  # version was replaced
         self._update_driver_version(drivermetadata_path, version)
 def _create_driver(path,
                    package_path,
                    dir_path,
                    driver_name,
                    mandatory=True):
     dir_to_zip = os.path.join(path, dir_path)
     if os.path.exists(dir_to_zip):
         zip_file_path = os.path.join(package_path, driver_name)
         ArchiveCreator.make_archive(zip_file_path, "zip", dir_to_zip)
     elif mandatory:
         raise click.ClickException(
             u"Invalid driver structure. Can't find '{}' driver folder.".
             format(dir_path))
Exemplo n.º 3
0
    def test_error_displayed_when_driver_generation_returns_error_code(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:
                response = Mock()
                response.status_code = 500
                response.content = "Error occurred"
                post_mock.return_value = response

                with patch("shellfoundry.utilities.driver_generator.click"
                           ) as click_mock:
                    click_mock.echo = MagicMock()

                    # 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")

                self.assertTrue(click_mock.echo.called,
                                "click should have been called")

        # Assert
        assertFileDoesNotExist(self, "nut-shell/src/data_model.py")
Exemplo n.º 4
0
    def test_error_displayed_when_failed_to_connect_to_cloudshell_server(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:
            mock_rest.side_effect = urllib2.URLError("connected failed")

            with patch("shellfoundry.utilities.driver_generator.click"
                       ) as click_mock:
                echo_mock = MagicMock()
                click_mock.echo = echo_mock

                # Act
                try:
                    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")
                except urllib2.URLError:
                    pass

                self.assertTrue(echo_mock.called,
                                "click should have been called")
                self.assertEqual(
                    echo_mock.call_args[0][0],
                    u"Login to CloudShell failed. Please verify the credentials in cloudshell_config.yml"
                )

        # Assert
        assertFileDoesNotExist(self, "nut-shell/src/data_model.py")
Exemplo n.º 5
0
    def test_error_displayed_when_driver_generation_returns_error_code(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:
                response = Mock()
                response.status_code = 500
                response.content = 'Error occurred'
                post_mock.return_value = response

                with patch('shellfoundry.utilities.driver_generator.click'
                           ) as click_mock:
                    click_mock.echo = MagicMock()

                    # 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')

                self.assertTrue(click_mock.echo.called,
                                'click should have been called')

        # Assert
        assertFileDoesNotExist(self, 'nut-shell/src/data_model.py')
Exemplo n.º 6
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.º 7
0
    def test_error_displayed_when_failed_to_connect_to_cloudshell_server(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:
            mock_rest.side_effect = urllib2.URLError('connected failed')

            with patch('shellfoundry.utilities.driver_generator.click'
                       ) as click_mock:
                echo_mock = MagicMock()
                click_mock.echo = echo_mock

                # Act
                try:
                    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')
                except urllib2.URLError:
                    pass

                self.assertTrue(echo_mock.called,
                                'click should have been called')
                self.assertEqual(
                    echo_mock.call_args[0][0],
                    u'Login to CloudShell failed. Please verify the credentials in cloudshell_config.yml'
                )

        # Assert
        assertFileDoesNotExist(self, 'nut-shell/src/data_model.py')
Exemplo n.º 8
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')
Exemplo n.º 9
0
 def _zip_package(package_path, path, package_name):
     zip_file_path = os.path.join(path, "dist", package_name)
     return ArchiveCreator.make_archive(zip_file_path, "zip", package_path)
 def _create_driver(path, package_path, shell_name):
     dir_to_zip = os.path.join(path, 'src')
     driver_name = shell_name + 'Driver'
     zip_file_path = os.path.join(package_path, driver_name)
     ArchiveCreator.make_archive(zip_file_path, 'zip', dir_to_zip)