def test_proper_error_message_displayed_when_login_failed(self):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml',
                           contents="""
shell:
    name: nut_shell
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml',
                           contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')
        mock_installer = Mock()
        mock_installer.install = Mock(
            side_effect=HTTPError('', 401, LOGIN_ERROR_MESSAGE, None, None))
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        with self.assertRaises(FatalError) as context:
            command_executor.install()

        # Assert
        self.assertTrue(
            str(context.exception) ==
            u'Login to CloudShell failed. Please verify the credentials in the config'
        )
    def test_when_config_files_exist_install_succeeds(self):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml', contents="""
shell:
    name: nut_shell
    driver: NutShellDriver
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml', contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')

        mock_installer = MagicMock()
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        command_executor.install()

        # Assert
        mock_installer.install.assert_called_once_with('nut_shell', InstallConfig('localhost', 9000, 'YOUR_USERNAME',
                                                                                  'YOUR_PASSWORD', 'Global'))
    def test_when_config_files_exist_install_succeeds(self, secho_mock):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml',
                           contents="""
shell:
    name: nut_shell
    driver: NutShellDriver
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml',
                           contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    author: AUTHOR
    online_mode: ONLINE_MODE
    template_location: TEMPLATE_LOCATION
    """)
        os.chdir('nut_shell')

        mock_installer = MagicMock()
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        command_executor.install()

        # Assert
        mock_installer.install.assert_called_once_with(
            'nut_shell',
            InstallConfig('localhost', 9000, 'YOUR_USERNAME', 'YOUR_PASSWORD',
                          'Global', "AUTHOR", 'ONLINE_MODE',
                          'TEMPLATE_LOCATION'))
        secho_mock.assert_any_call('Successfully installed shell', fg='green')
    def test_proper_error_appears_when_old_shell_installation_fails(self):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml',
                           contents="""
shell:
    name: nut_shell
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml',
                           contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')
        mock_installer = Mock()
        ex_msg = 'Quali Error: some fancy error here'
        mock_installer.install = Mock(side_effect=Exception(ex_msg))
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        with self.assertRaises(FatalError) as context:
            command_executor.install()

        # Assert
        self.assertTrue(
            context.exception.message ==
            u"Failed to install shell. CloudShell responded with: '{}'".format(
                ex_msg))
    def test_proper_error_appears_when_connection_to_cs_failed(self):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml',
                           contents="""
shell:
    name: nut_shell
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml',
                           contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')
        mock_installer = Mock()
        mock_installer.install = Mock(side_effect=URLError(''))
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        with self.assertRaises(FatalError) as context:
            command_executor.install()

        # Assert
        self.assertTrue(
            context.exception.message ==
            u'Connection to CloudShell Server failed. Please make sure it is up and running properly.'
        )
    def test_proper_error_message_when_non_authentication_http_error_raised(
            self):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml',
                           contents="""
shell:
    name: nut_shell
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml',
                           contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')
        mock_installer = Mock()
        mock_installer.install = Mock(
            side_effect=HTTPError('', 404, LOGIN_ERROR_MESSAGE, None, None))
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        with self.assertRaises(FatalError) as context:
            command_executor.install()

        # Assert
        self.assertTrue(
            str(context.exception) ==
            u"Failed to install shell. CloudShell responded with: '{}'".format(
                'Login failed for user: YOUR_USERNAME. '
                'Please make sure the username and password are correct.'),
            "Actual: {}".format(context.exception))
    def test_install_layer_one_shell(self, secho_mock):
        # Arrange
        self.fs.CreateFile('cloudshell-L1-test/datamodel/datamodel.xml')
        os.chdir('cloudshell-L1-test')

        mock_shell_package_installer = MagicMock()
        command_executor = InstallCommandExecutor(
            shell_package_installer=mock_shell_package_installer)

        # Act
        command_executor.install()

        # Assert
        secho_mock.assert_any_call(
            "Installing a L1 shell directly via shellfoundry is not supported. "
            "Please follow the L1 shell import procedure described in help.quali.com.",
            fg="yellow")
    def test_tosca_based_shell_installed_when_tosca_meta_file_exists(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')

        os.chdir('nut-shell')

        mock_shell_package_installer = MagicMock()
        command_executor = InstallCommandExecutor(
            shell_package_installer=mock_shell_package_installer)

        # Act
        command_executor.install()

        # Assert
        self.assertTrue(mock_shell_package_installer.install.called)
    def test_proper_error_message_displayed_when_login_failed(self, echo_mock):
        # Arrange
        self.fs.CreateFile('nut_shell/shell.yml', contents="""
shell:
    name: nut_shell
    """)
        self.fs.CreateFile('nut_shell/cloudshell_config.yml', contents="""
install:
    host: localhost
    port: 9000
    username: YOUR_USERNAME
    password: YOUR_PASSWORD
    domain: Global
    """)
        os.chdir('nut_shell')
        mock_installer = Mock()
        mock_installer.install = Mock(side_effect=HTTPError('', '', LOGIN_ERROR_MESSAGE, None, None))
        command_executor = InstallCommandExecutor(installer=mock_installer)

        # Act
        command_executor.install()

        # Assert
        echo_mock.assert_called_once_with(u'Login to CloudShell failed. Please verify the credentials in cloudshell_config.yml')
def main(args):

    #
    # CLI
    #
    parser = ArgumentParser(description='create new TG release',
                            formatter_class=RawDescriptionHelpFormatter)
    parser.add_argument("-r", "--release", help="New release version")
    parser.add_argument("-m", "--message", help="New commit message")
    parsed_args = parser.parse_args(args)

    #
    # Write new version
    #
    with open("shell.yml", 'r') as f:
        shell = yaml.safe_load(f)
    shell['shell']['version'] = parsed_args.release
    with open("shell.yml", 'w') as f:
        yaml.safe_dump(shell, f, default_flow_style=False)

    with open("version.txt", 'w') as f:
        f.write(parsed_args.release)

    drivermetadata = ET.parse('src/drivermetadata.xml')
    driver = drivermetadata.getroot()
    driver.attrib['Version'] = parsed_args.release
    drivermetadata.write('src/drivermetadata.xml')

    #
    # Shellfoundry
    #
    PackCommandExecutor().pack()
    DistCommandExecutor().dist()
    InstallCommandExecutor().install()

    #
    # git
    #
    if parsed_args.message:
        repo = Repo('.')
        repo.git.add('.')
        repo.git.commit('-m version {}'.format(parsed_args.message))
        repo.git.push()
示例#11
0
def install():
    """
    Installs the shell package into CloudShell
    """
    PackCommandExecutor().pack()
    InstallCommandExecutor().install()
示例#12
0
def install():
    """
    Install the shell package into CloudShell.
    """
    InstallCommandExecutor().install()