예제 #1
0
    def test_link_artifact_to_current(self):
        """
        Create a link in the parent directory for this artifact,
        pointing to the directory of the artifact, with the name "current".
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()

        transport = SshTransport(self.archive)
        with mock.patch.object(
                transport, "_get_ssh_clients",
                return_value=(mock_ssh, mock_sftp)):
            transport.start()
            current_dir = transport.link_to_current("/project/1234/temp.gz")
        mock_ssh.exec_command.assert_has_calls(
            [mock.call('cd "/var/tmp/project" && rm -f current '
                       '&& ln -sf "1234" current')])
        self.assertEqual("/var/tmp/project/current", current_dir)
        mock_ssh.close.assert_called_once()
예제 #2
0
    def test_link_artifact_to_current(self):
        """
        Create a link in the parent directory for this artifact,
        pointing to the directory of the artifact, with the name "current".
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()

        transport = SshTransport(self.archive)
        with mock.patch.object(transport,
                               "_get_ssh_clients",
                               return_value=(mock_ssh, mock_sftp)):
            transport.start()
            current_dir = transport.link_to_current("/project/1234/temp.gz")
        mock_ssh.exec_command.assert_has_calls([
            mock.call('cd "/var/tmp/project" && rm -f current '
                      '&& ln -sf "1234" current')
        ])
        self.assertEqual("/var/tmp/project/current", current_dir)
        mock_ssh.close.assert_called_once()
예제 #3
0
    def test_link_filename_to_filename(self):
        """
        archive_file should ensure that there's a directory relative to the
        base to hold the file, and then stream the file to the remote server.
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()

        transport = SshTransport(self.archive)
        with mock.patch.object(
                transport, "_get_ssh_clients",
                return_value=(mock_ssh, mock_sftp)):
            transport.start()
            transport.link_filename_to_filename(
                "/temp/temp.gz", "/temp2/temp.gz")
        mock_ssh.exec_command.assert_has_calls(
            [mock.call("mkdir -p `dirname /var/tmp/temp2/temp.gz`"),
             mock.call('ln "/var/tmp/temp/temp.gz" "/var/tmp/temp2/temp.gz"')])

        mock_ssh.close.assert_called_once()
예제 #4
0
    def test_link_filename_to_filename(self):
        """
        archive_file should ensure that there's a directory relative to the
        base to hold the file, and then stream the file to the remote server.
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()

        transport = SshTransport(self.archive)
        with mock.patch.object(transport,
                               "_get_ssh_clients",
                               return_value=(mock_ssh, mock_sftp)):
            transport.start()
            transport.link_filename_to_filename("/temp/temp.gz",
                                                "/temp2/temp.gz")
        mock_ssh.exec_command.assert_has_calls([
            mock.call("mkdir -p `dirname /var/tmp/temp2/temp.gz`"),
            mock.call('ln "/var/tmp/temp/temp.gz" "/var/tmp/temp2/temp.gz"')
        ])

        mock_ssh.close.assert_called_once()
예제 #5
0
    def test_archive_file(self):
        """
        archive_file should ensure that there's a directory relative to the base
        to hold the file, and then stream the file to the remote server.
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()
        fakefile = StringIO(u"This is the artifact")

        transport = SshTransport(self.archive)
        with mock.patch.object(
                transport, "_get_ssh_clients",
                return_value=(mock_ssh, mock_sftp)):
            transport.start()
            transport.archive_file(fakefile, "/temp/temp.gz")
        mock_ssh.exec_command.assert_called_once_with(
            "mkdir -p `dirname /var/tmp/temp/temp.gz`")

        mock_sftp.stream_file_to_remote.assert_called_once_with(
            fakefile, "/var/tmp/temp/temp.gz")

        mock_ssh.close.assert_called_once()
예제 #6
0
    def test_archive_file(self):
        """
        archive_file should ensure that there's a directory relative to the
        base to hold the file, and then stream the file to the remote server.
        """
        mock_ssh = mock.Mock()
        mock_stdout = mock.Mock()
        mock_ssh.exec_command.return_value = None, mock_stdout, None
        mock_sftp = mock.Mock()
        fakefile = StringIO(u"This is the artifact")

        transport = SshTransport(self.archive)
        with mock.patch.object(transport,
                               "_get_ssh_clients",
                               return_value=(mock_ssh, mock_sftp)):
            transport.start()
            transport.archive_file(fakefile, "/temp/temp.gz")
        mock_ssh.exec_command.assert_called_once_with(
            "mkdir -p `dirname /var/tmp/temp/temp.gz`")

        mock_sftp.stream_file_to_remote.assert_called_once_with(
            fakefile, "/var/tmp/temp/temp.gz")

        mock_ssh.close.assert_called_once()