Ejemplo n.º 1
0
    def test_psuedo_install_fail(self):
        # do a psuedo install that fails
        mystr = "GOODBYE MOM"
        cfg = {
            'stages': ['early'],
            'early_commands': {
                'mycmd': ["sh", "-c", "echo " + mystr + "; exit 9;"]
            },
            'install': {
                'error_tarfile': None
            }
        }

        out, err, rc, log_contents = self.run_install(cfg)

        # the version string and users command output should be in output
        self.assertIn(version.version_string(), out)
        self.assertIn(version.version_string(), log_contents)
        self.assertIn(mystr, out)
        # rc is not expected to match the 'exit 9' above, but should not be 0.
        self.assertNotEqual(0, rc)

        self.assertIn(INSTALL_START_MSG, out)
        self.assertIn(INSTALL_START_MSG, log_contents)

        # from INSTALL_FAIL_MSG, without exception
        failmsg = "curtin: Installation failed"
        self.assertIn(failmsg, err)
        self.assertIn(failmsg, log_contents)
Ejemplo n.º 2
0
    def test_psuedo_install(self):
        # do a install that has only a early stage and only one command.
        mystr = "HI MOM"
        cfg = {
            'stages': ['early'],
            'early_commands': {
                'mycmd': ["sh", "-c", "echo " + mystr]
            }
        }

        out, err, rc, log_contents = self.run_install(cfg)
        print("out=%s" % out)
        print("err=%s" % err)

        # the version string and users command output should be in output
        self.assertIn(version.version_string(), out)
        self.assertIn(mystr, out)
        self.assertEqual(0, rc)

        self.assertIn(INSTALL_START_MSG, out)
        self.assertIn(INSTALL_START_MSG, log_contents)
        self.assertIn(INSTALL_PASS_MSG, out)
        self.assertIn(INSTALL_PASS_MSG, log_contents)
        # log should also have the version string.
        self.assertIn(version.version_string(), log_contents)
Ejemplo n.º 3
0
    def test_old_version(self):
        self.mock_path.exists.return_value = False
        self.mock_subp.return_value = "".encode('utf-8')

        ver_string = version.version_string()

        self.assertEqual(old_version, ver_string)
Ejemplo n.º 4
0
    def test_git_describe_version_exception(self, mock_getcwd):
        self.mock_path.exists.return_value = True
        mock_getcwd.return_value = "/tmp/foo"
        self.mock_subp.side_effect = subprocess.CalledProcessError(1, 'foo')

        ver_string = version.version_string()
        self.assertEqual(old_version, ver_string)
Ejemplo n.º 5
0
    def test_git_describe_version(self):
        self.mock_path.exists.return_value = True
        git_describe = old_version + "-13-g90fa654f"
        self.mock_subp.return_value = git_describe.encode("utf-8")

        ver_string = version.version_string()
        self.assertEqual(git_describe, ver_string)
Ejemplo n.º 6
0
    def test_packaged_version(self, mock_getcwd):
        original_pkg_string = version._PACKAGED_VERSION
        test_pkg_version = '9.8.7-curtin-0ubuntu12'
        version._PACKAGED_VERSION = test_pkg_version

        ver_string = version.version_string()

        # check we got the packaged version string set
        self.assertEqual(test_pkg_version, ver_string)
        # make sure we didn't take any other path
        self.assertEqual([], self.mock_path.call_args_list)
        self.assertEqual([], mock_getcwd.call_args_list)
        self.assertEqual([], self.mock_subp.call_args_list)

        version._PACKAGED_VERSION = original_pkg_string
Ejemplo n.º 7
0
    def test_curtin_help_has_hacked_version(self):
        # ensure that we are running the output of pack, and not the venv
        # Change 'version.py' to contain a different string than the venv
        # has, and verify that python --help has that changed string, then
        # change it back for other tests.
        version_py = os.path.join(self.extract_dir, 'curtin', 'version.py')
        hack_version_str = "MY_VERSION_STRING"
        orig_contents = util.load_file(version_py)
        hacked_contents = orig_contents.replace(version.version_string(),
                                                hack_version_str)
        self.assertIn(hack_version_str, hacked_contents)
        try:
            util.write_file(version_py, hacked_contents)
            remove_pyc_for_file(version_py)
            out, err = self.run_main(['--help'])
        finally:
            util.write_file(version_py, orig_contents)
            remove_pyc_for_file(version_py)

        self.assertIn(hack_version_str, out)
Ejemplo n.º 8
0
def handle_pollinate_user_agent(cfg, target):
    """Configure the pollinate user-agent if provided configuration

    pollinate:
        user_agent: false  # disable writing out a user-agent string

    # custom agent key/value pairs
    pollinate:
       user_agent:
          key1: value1
          key2: value2

    No config will result in curtin fetching:
      curtin version
      maas version (via endpoint URL, if present)
    """

    pcfg = cfg.get('pollinate')
    if not isinstance(pcfg, dict):
        pcfg = {'user_agent': {}}

    uacfg = pcfg.get('user_agent', {})
    if uacfg is False:
        return

    # set curtin version
    uacfg['curtin'] = curtin_version.version_string()

    # maas configures a curtin reporting webhook handler with
    # an endpoint URL.  This url is used to query the MAAS REST
    # api to extract the exact maas version.
    maas_reporting = cfg.get('reporting', {}).get('maas', None)
    if maas_reporting:
        endpoint = maas_reporting.get('endpoint')
        maas_version = get_maas_version(endpoint)
        if maas_version:
            uacfg['maas'] = maas_version['version']

    inject_pollinate_user_agent_config(uacfg, target)
Ejemplo n.º 9
0
    def test_dpkg_version_exception(self):
        self.mock_path.exists.return_value = True
        self.mock_subp.side_effect = subprocess.CalledProcessError(1, '')

        ver_string = version.version_string()
        self.assertEqual(old_version, ver_string)
Ejemplo n.º 10
0
from curtin import config
from curtin import util
from curtin import version
from curtin.log import LOG, logged_time
from curtin.reporter.legacy import load_reporter
from curtin.reporter import events
from . import populate_one_subcmd

INSTALL_LOG = "/var/log/curtin/install.log"
# Upon error, curtin creates a tar of all related logs at ERROR_TARFILE
ERROR_TARFILE = '/var/log/curtin/curtin-error-logs.tar'
SAVE_INSTALL_LOG = '/root/curtin-install.log'
SAVE_INSTALL_CONFIG = '/root/curtin-install-cfg.yaml'

INSTALL_START_MSG = ("curtin: Installation started. (%s)" %
                     version.version_string())
INSTALL_PASS_MSG = "curtin: Installation finished."
INSTALL_FAIL_MSG = "curtin: Installation failed with exception: {exception}"

STAGE_DESCRIPTIONS = {
    'early': 'preparing for installation',
    'partitioning': 'configuring storage',
    'network': 'configuring network',
    'extract': 'writing install sources to disk',
    'curthooks': 'configuring installed system',
    'hook': 'finalizing installation',
    'late': 'executing late commands',
}

CONFIG_BUILTIN = {
    'sources': {},
Ejemplo n.º 11
0
    from urllib import request as _u_re  # pylint: disable=no-name-in-module
    from urllib import error as _u_e     # pylint: disable=no-name-in-module
    from urllib.parse import urlparse    # pylint: disable=no-name-in-module
    urllib_request = _u_re
    urllib_error = _u_e
except ImportError:
    # python2
    import urllib2 as urllib_request
    import urllib2 as urllib_error
    from urlparse import urlparse  # pylint: disable=import-error

from .log import LOG

error = urllib_error

DEFAULT_HEADERS = {'User-Agent': 'Curtin/' + version.version_string()}


class _ReRaisedException(Exception):
    exc = None
    """this exists only as an exception type that was re-raised by
    an exception_cb, so code can know to handle it specially"""
    def __init__(self, exc):
        self.exc = exc


class UrlReader(object):
    fp = None

    def __init__(self, url, headers=None, data=None):
        headers = _get_headers(headers)
Ejemplo n.º 12
0
 def test_curtin_version(self):
     # test curtin version subcommand outputs expected version.
     out, err = self.run_main(['version'])
     self.assertEqual(version.version_string(), out.strip())
Ejemplo n.º 13
0
 def test_curtin_help_has_version(self):
     # test curtin --help has version
     out, err = self.run_main(['--help'])
     self.assertIn(version.version_string(), out)