usr/src/cmd/distro_const/__init__.py
author Ethan Quach <Ethan.Quach@sun.com>
Tue, 31 May 2011 14:21:09 -0700
changeset 1160 6f7e708c38ec
parent 1111 0c6c862af34f
child 1163 b46f8cd05817
permissions -rw-r--r--
16257 Support for zones configuration and installation should be included in AI 7041915 TransferFiles ICT should support transferring a directory that is more than one level deep. 7049824 System installed via AI ends up with incorrect mountpoints for shared ZFS datasets
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
947
29603af1b942 6999599 Missing shebang lines in python modules leads to incorrect dependency generation
Keith Mitchell <keith.mitchell@oracle.com>
parents: 649
diff changeset
     1
#!/usr/bin/python
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     2
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     3
# CDDL HEADER START
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     4
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     8
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    12
# and limitations under the License.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    13
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    19
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    20
# CDDL HEADER END
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    21
#
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    22
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    23
#
974
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
    24
# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    25
#
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    26
649
ba353c37b287 12670 Change nested try/except in distro_const.py missed during 2.6 python porting
Clay Baenziger <ClayB@OpenSolaris.ORG>
parents: 609
diff changeset
    27
"""init module for the distribution constructor"""
197
ac1383e6038c 2618 Move install related modules in slim_source to a common place
Karen Tung <Karen.Tung@Sun.COM>
parents:
diff changeset
    28
1160
6f7e708c38ec 16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents: 1111
diff changeset
    29
__all__ = ["cli", "distro_const", "execution_checkpoint", "distro_spec"]
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    30
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    31
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    32
import logging
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    33
import optparse
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    34
import os
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    35
import shutil
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    36
import sys
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    37
import time
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    38
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    39
import distro_spec
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    40
import execution_checkpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    41
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    42
import osol_install.errsvc as errsvc
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    43
import solaris_install.transfer.info as transfer
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    44
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    45
from subprocess import Popen, PIPE, CalledProcessError
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    46
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    47
from osol_install.install_utils import set_http_proxy
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    48
from osol_install.liberrsvc import ES_DATA_EXCEPTION
1111
0c6c862af34f 7038421 Provide a boot checkpoint implementation based on pybootmgmt
Niall Power <niall@brawndo.local>
parents: 1077
diff changeset
    49
from solaris_install.boot.boot_spec import BootMods
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    50
from solaris_install.data_object import DataObject, ObjectNotFoundError
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    51
from solaris_install.data_object.cache import DataObjectCache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    52
from solaris_install.data_object.data_dict import DataObjectDict
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    53
from solaris_install.distro_const.execution_checkpoint import Execution
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    54
from solaris_install.distro_const.distro_spec import Distro
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    55
from solaris_install.engine import FileNotFoundError, InstallEngine, \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    56
    NoDatasetError, RollbackError, UsageError, UnknownChkptError
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    57
from solaris_install.engine import INSTALL_LOGGER_NAME
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    58
from solaris_install.logger import DEFAULTLOG, FileHandler, InstallFormatter
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    59
from solaris_install.manifest.parser import ManifestError
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
    60
from solaris_install.target import Target
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
    61
from solaris_install.target.logical import Filesystem, Zpool
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
    62
from solaris_install.transfer.info import Destination, Dir, Image, Software, \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
    63
    Source
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    64
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    65
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    66
# DOC label for entries pertaining to the distribution constructor
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    67
# All 'volatile' entries are stored in DC_LABEL and all 'persistent'
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    68
# entries are stored in DC_PERS_LABEL
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    69
DC_LABEL = "DC specific"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    70
DC_PERS_LABEL = "DC specific persistent"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    71
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    72
# manifest parser dictionary.  These values are used to register the manifest
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    73
# parser checkpoint with the engine
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    74
MP_DICT = {}
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    75
MP_DICT["name"] = "manifest-parser"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    76
MP_DICT["mod_path"] = "solaris_install/manifest/parser"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    77
MP_DICT["class"] = "ManifestParser"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    78
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    79
# target instantiation dictionary.  These values are used to register the
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    80
# ti checkpoint with the engine
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    81
TI_DICT = {}
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    82
TI_DICT["name"] = "target-instantiation"
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
    83
TI_DICT["mod_path"] = "solaris_install/target/instantiation"
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    84
TI_DICT["class"] = "TargetInstantiation"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    85
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    86
DC_LOCKFILE = "distro_const.lock"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    87
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    88
# create a logger for DC
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    89
DC_LOGGER = None
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    90
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
    91
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    92
class Lockfile(object):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    93
    """ Lockfile - context manager for locking the distro_const dataset to
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    94
    prevent multiple invocations of distro_const from running at the same time
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    95
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    96
    def __init__(self, filename):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    97
        """ constructor for class.  filename is the path of the file to use to
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    98
        lock the dataset
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
    99
        """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   100
        self.filename = filename
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   101
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   102
    def __enter__(self):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   103
        """ class method which checks for the lockfile before creating one.  If
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   104
        the lockfile exists, exit with an error
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   105
        """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   106
        if os.path.exists(self.filename):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   107
            raise RuntimeError("distro_const: An instance of distro_const " \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   108
                               "is already running in " \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   109
                               "%s" % os.path.split(self.filename)[0])
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   110
        else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   111
            # touch the lockfile
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   112
            with open(self.filename, "w"):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   113
                pass
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   114
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   115
    def __exit__(self, *exc_info):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   116
        """ class method to remove the lockfile
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   117
        """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   118
        if os.path.exists(self.filename):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   119
            try:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   120
                os.remove(self.filename)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   121
            except BaseException as err:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   122
                raise RuntimeError("Could not remove %s: %s" % \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   123
                                   (self.filename, err))
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   124
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   125
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   126
class DCScreenHandler(logging.Formatter):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   127
    """ DC-specific StreamHandler class.  Suppresses traceback printing to the
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   128
    screen by overloading the format() method
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   129
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   130
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   131
    def format(self, record):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   132
        """ overloaded method to prevent the traceback from being printed
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   133
        """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   134
        record.message = record.getMessage()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   135
        record.asctime = self.formatTime(record, self.datefmt)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   136
        s = self._fmt % record.__dict__
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   137
        return s
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   138
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   139
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   140
def parse_args(baseargs=None):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   141
    """ parse_args() - function used to parse the command line arguments to
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   142
    distro_const.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   143
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   144
    if baseargs is None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   145
        baseargs = sys.argv[1:]
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   146
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   147
    usage = "%prog build [-v] [-r <checkpoint name>] " + \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   148
            "[-p <checkpoint name>] " + \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   149
            "[-l] manifest"
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   150
    parser = optparse.OptionParser(usage=usage)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   151
    parser.add_option("-v", "--verbose", dest="verbose", default=False,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   152
                      action="store_true", help="Specifies verbose mode")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   153
    parser.add_option("-r", "--resume", dest="resume_checkpoint",
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   154
                      help="Checkpoint to resume execution from")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   155
    parser.add_option("-p", "--pause", dest="pause_checkpoint",
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   156
                      help="Checkpoint to pause execution on")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   157
    parser.add_option("-l", "--list", dest="list_checkpoints",
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   158
                      action="store_true",
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   159
                      help="List all possible checkpoints")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   160
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   161
    (options, args) = parser.parse_args(baseargs)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   162
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   163
    # verify there are exactly two arguments (subcommand and manifest)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   164
    if not args:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   165
        parser.error("subcommand and manifest not specified")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   166
    # currently only the 'build' subcommand is supported
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   167
    elif args[0] != "build":
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   168
        parser.error("invalid or missing subcommand")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   169
    elif len(args) != 2:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   170
        parser.error("invalid number of arguments to distro_const")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   171
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   172
    return (options, args)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   173
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   174
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   175
def set_stream_handler(DC_LOGGER, list_cps, verbose):
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   176
    """ function to setup the stream_handler of the logging module for output
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   177
    to the screen.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   178
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   179
    # create a simple StreamHandler to output messages to the screen
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   180
    screen_sh = logging.StreamHandler()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   181
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   182
    # set the verbosity of the output
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   183
    if verbose:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   184
        screen_sh.setLevel(logging.DEBUG)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   185
    else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   186
        screen_sh.setLevel(logging.INFO)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   187
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   188
    # set the columns.  If the user only wants to list the checkpoints, omit
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   189
    # the timestamps
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   190
    if list_cps:
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   191
        fmt = "%(message)s"
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   192
        screen_sh.setFormatter(DCScreenHandler(fmt=fmt))
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   193
    else:
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   194
        fmt = "%(asctime)-11s %(message)s"
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   195
        datefmt = "%H:%M:%S"
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   196
        screen_sh.setFormatter(DCScreenHandler(fmt=fmt, datefmt=datefmt))
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   197
    DC_LOGGER.addHandler(screen_sh)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   198
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   199
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   200
def register_checkpoints(DC_LOGGER):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   201
    """ register each checkpoint in the execution section of the
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   202
    manifest with the InstallEngine.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   203
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   204
    Also set the stop_on_error property of the InstallEngine based on what
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   205
    that property is set to in the manifest.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   206
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   207
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   208
    doc = eng.data_object_cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   209
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   210
    # get the execution object from the DOC that contains all of the
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   211
    # checkpoint objects as the children
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   212
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   213
    # get the execution_list from the Distro object
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   214
    distro_obj = doc.volatile.get_first_child(class_type=Distro)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   215
    execution_obj = distro_obj.get_first_child(class_type=Execution)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   216
    if execution_obj is None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   217
        raise RuntimeError("No Execution section found in the manifest")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   218
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   219
    # get_children, with no parameters, will return an empty list if there are
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   220
    # no children
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   221
    checkpoints = execution_obj.get_children()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   222
    if len(checkpoints) == 0:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   223
        raise RuntimeError("No checkpoints found in the Execution section "
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   224
                           "of the manifest")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   225
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   226
    # set stop_on_error commensurate with what's specified in the manifest
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   227
    eng.stop_on_error = (execution_obj.stop_on_error.capitalize() == "True")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   228
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   229
    # register the checkpoints with the engine
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   230
    registered_checkpoints = []
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   231
    for checkpoint in checkpoints:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   232
        try:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   233
            DC_LOGGER.debug("Registering Checkpoint:  " + checkpoint.name)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   234
            eng.register_checkpoint(checkpoint.name, checkpoint.mod_path,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   235
                checkpoint.checkpoint_class, insert_before=None,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   236
                loglevel=checkpoint.log_level, args=checkpoint.args,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   237
                kwargs=checkpoint.kwargs)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   238
974
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
   239
        except ImportError as err:
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   240
            DC_LOGGER.exception("Error registering checkpoint "
974
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
   241
                                "'%s'\n" % checkpoint.name + \
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
   242
                                "Check the 'mod_path' and 'checkpoint_class' "
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
   243
                                "specified for this checkpoint")
356b23696c62 7009607 DC doesn't abort when a checkpoint fails to register
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 968
diff changeset
   244
            raise
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   245
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   246
        registered_checkpoints.append((checkpoint.name, checkpoint.desc))
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   247
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   248
    return registered_checkpoints
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   249
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   250
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   251
def execute_checkpoint(log=DEFAULTLOG, resume_checkpoint=None,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   252
                       pause_checkpoint=None):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   253
    """ wrapper to the execute_checkpoints (and friends) methods
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   254
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   255
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   256
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   257
    if resume_checkpoint is not None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   258
        (status, failed_cps) = eng.resume_execute_checkpoints(
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   259
            start_from=resume_checkpoint, pause_before=pause_checkpoint,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   260
            dry_run=False, callback=None)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   261
    else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   262
        (status, failed_cps) = eng.execute_checkpoints(start_from=None,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   263
            pause_before=pause_checkpoint, dry_run=False, callback=None)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   264
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   265
    if status != InstallEngine.EXEC_SUCCESS:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   266
        for failed_cp in failed_cps:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   267
            for err in errsvc.get_errors_by_mod_id(failed_cp):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   268
                DC_LOGGER.info("'%s' checkpoint failed" % failed_cp)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   269
                DC_LOGGER.info(err.error_data[ES_DATA_EXCEPTION])
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   270
                # if a CalledProcessError is raised during execution of a
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   271
                # checkpoint, make sure the strerror() is also logged to give
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   272
                # the user additional feedback
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   273
                if isinstance(err.error_data[ES_DATA_EXCEPTION],
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   274
                              CalledProcessError):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   275
                    DC_LOGGER.debug(os.strerror(
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   276
                        err.error_data[ES_DATA_EXCEPTION].returncode))
967
524de3368b08 7007793 target instantiation does not handle 'preserve' action correctly
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 960
diff changeset
   277
        raise RuntimeError("Please check the log for additional error "
1047
22098f6a68c4 7024495 DC changes for PSARC 2010/368 EOF 32-bit x86 kernel support
Mary Ding <mary.ding@oracle.com>
parents: 974
diff changeset
   278
                           "messages. \nLog: " + log)
22098f6a68c4 7024495 DC changes for PSARC 2010/368 EOF 32-bit x86 kernel support
Mary Ding <mary.ding@oracle.com>
parents: 974
diff changeset
   279
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   280
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   281
def parse_manifest(manifest):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   282
    """ function to parse the manifest
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   283
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   284
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   285
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   286
    kwargs = dict()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   287
    kwargs["call_xinclude"] = True
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   288
    args = [manifest]
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   289
    eng.register_checkpoint(MP_DICT["name"], MP_DICT["mod_path"],
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   290
                            MP_DICT["class"], args=args, kwargs=kwargs)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   291
    execute_checkpoint()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   292
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   293
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   294
def validate_target():
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   295
    """ validate_target() - function to validate the target element specified
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   296
    in the manifest.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   297
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   298
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   299
    doc = eng.data_object_cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   300
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   301
    # retrieve the build dataset
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   302
    build_datasets = doc.get_descendants(class_type=Filesystem)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   303
    if len(build_datasets) > 1:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   304
        raise RuntimeError("More than one dataset specified as the build "
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   305
                           "dataset")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   306
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   307
    base_dataset = build_datasets[0].name
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   308
    base_action = build_datasets[0].action
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   309
    base_mountpoint = build_datasets[0].mountpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   310
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   311
    # verify the base_action is not "delete" for the Filesystem
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   312
    if base_action == "delete":
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   313
        raise RuntimeError("distro_const: 'delete' action not supported "
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   314
                           "for Filesystems")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   315
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   316
    # get the zpool name and action
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   317
    build_zpool = doc.get_descendants(class_type=Zpool)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   318
    if len(build_zpool) > 1:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   319
        raise RuntimeError("More than one zpool specified")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   320
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   321
    zpool_name = build_zpool[0].name
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   322
    zpool_action = build_zpool[0].action
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   323
    zpool_mountpoint = build_zpool[0].mountpoint
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   324
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   325
    if zpool_action == "delete":
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   326
        raise RuntimeError("distro_const: 'delete' action not supported "
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   327
                           "for Zpools")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   328
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   329
    # if the user has selected "create" for the action, verify the zpool is
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   330
    # not the bootfs zpool since there is an implied "delete" before any
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   331
    # "create" actions in TI
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   332
    elif zpool_action == "create":
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   333
        if is_root_pool(zpool_name):
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   334
            raise RuntimeError("distro_const: 'create' action not allowed "
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   335
                               "on a build dataset that is also a root "
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   336
                               "pool: " + zpool_name)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   337
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   338
        # since the zpool_action is "create", unless the mountpoint of the
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   339
        # base_dataset is explictly set, it will be set to None.
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   340
        if base_mountpoint is None:
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   341
            # let ZFS figure out the mountpoint
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   342
            if zpool_mountpoint is None:
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   343
                base_mountpoint = os.path.join("/", base_dataset)
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   344
            else:
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   345
                # if the mountpoint has been specified, strip the zpool name
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   346
                # from the dataset name.
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   347
                fixed_name = "/".join(base_dataset.split("/")[1:])
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   348
                base_mountpoint = os.path.join(zpool_mountpoint, fixed_name)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   349
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   350
    return(zpool_name, base_dataset, base_action, base_mountpoint)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   351
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   352
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   353
def setup_build_dataset(zpool_name, base_dataset, base_action, base_dataset_mp,
968
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   354
                        resume_checkpoint=None, execute=True):
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   355
    """ Setup the build datasets for use by DC. This includes setting up:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   356
    - top level build dataset
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   357
    - a child dataset named 'build_data'
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   358
    - a child dataset named 'media'
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   359
    - a child dataset named 'logs'
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   360
    - a snapshot of the empty build_data dataset - build_data@empty
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   361
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   362
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   363
    doc = eng.data_object_cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   364
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   365
    # register an internal TI checkpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   366
    eng.register_checkpoint(TI_DICT["name"], TI_DICT["mod_path"],
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   367
                            TI_DICT["class"])
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   368
968
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   369
    if not execute:
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   370
        return
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   371
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   372
    build_data = Filesystem(os.path.join(zpool_name, base_dataset,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   373
                                         "build_data"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   374
    empty_snap = Filesystem(os.path.join(zpool_name, base_dataset,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   375
                                         "build_data@empty"))
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   376
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   377
    # set the other mountpoints
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   378
    build_data_mp = os.path.join(base_dataset_mp, "build_data")
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   379
    logs_mp = os.path.join(base_dataset_mp, "logs")
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   380
    media_mp = os.path.join(base_dataset_mp, "media")
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   381
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   382
    # if resume_checkpoint is not None, ensure that the build datasets do
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   383
    # actually exist
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   384
    if resume_checkpoint is not None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   385
        if base_dataset_mp is None or \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   386
           build_data_mp is None or \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   387
           logs_mp is None or \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   388
           media_mp is None or\
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   389
           not empty_snap.exists:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   390
            raise RuntimeError("Build dataset not correctly setup.  "
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   391
                               "distro_const cannot be resumed.")
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   392
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   393
    # check for the existence of a lock file, bail out
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   394
    # if one exists.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   395
    if base_dataset_mp is not None and os.path.exists(base_dataset_mp):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   396
        if os.path.exists(os.path.join(base_dataset_mp, DC_LOCKFILE)):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   397
            raise RuntimeError("distro_const: An instance of distro_const " \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   398
                               "is already running in " + base_dataset_mp)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   399
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   400
    # create DOC nodes
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   401
    build_data_node = Filesystem(os.path.join(base_dataset, "build_data"))
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   402
    build_data_node.mountpoint = build_data_mp
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   403
    logs_node = Filesystem(os.path.join(base_dataset, "logs"))
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   404
    logs_node.mountpoint = logs_mp
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   405
    media_node = Filesystem(os.path.join(base_dataset, "media"))
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   406
    media_node.mountpoint = media_mp
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   407
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   408
    if base_action == "preserve":
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   409
        # check to see if base_dataset/build_data@empty exists.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   410
        if resume_checkpoint is None and empty_snap.exists:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   411
            # rollback the dataset only if DC is not resuming from a specific
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   412
            # checkpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   413
            build_data.rollback("empty", recursive=True)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   414
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   415
    build_data_node.action = base_action
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   416
    logs_node.action = base_action
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   417
    media_node.action = base_action
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   418
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   419
    # insert all three nodes.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   420
    zpool = doc.get_descendants(class_type=Zpool)[0]
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   421
    zpool.insert_children([build_data_node, logs_node, media_node])
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   422
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   423
    execute_checkpoint()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   424
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   425
    # the from_xml() call of Filesystem tries to manually set the mountpoint of
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   426
    # the base dataset.  In doing that, it makes assumptions about how ZFS
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   427
    # determines the mountpoint of the dataset.  Now that ZFS has created the
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   428
    # dataset, query ZFS to set the mountpoint based on what ZFS set it to.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   429
    base_dataset_object = Filesystem(os.path.join(zpool_name, base_dataset))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   430
    base_dataset_mp = base_dataset_object.get("mountpoint")
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   431
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   432
    # (re)set the other mountpoints
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   433
    build_data_mp = os.path.join(base_dataset_mp, "build_data")
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   434
    logs_mp = os.path.join(base_dataset_mp, "logs")
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   435
    media_mp = os.path.join(base_dataset_mp, "media")
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   436
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   437
    # create the @empty snapshot if needed
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   438
    if not empty_snap.exists:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   439
        build_data.snapshot("empty")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   440
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   441
    DC_LOGGER.info("Build datasets successfully setup")
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   442
    return (base_dataset_mp, build_data_mp, logs_mp, media_mp)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   443
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   444
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   445
def dc_set_http_proxy(DC_LOGGER):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   446
    """ set the http_proxy and HTTP_PROXY environment variables
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   447
    if an http_proxy is specified in the manifest.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   448
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   449
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   450
    doc = eng.data_object_cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   451
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   452
    # get the Distro object from the DOC that contains all of the
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   453
    # checkpoint objects as the children
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   454
    distro = doc.volatile.get_descendants(class_type=Distro)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   455
    if len(distro) == 0:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   456
        return
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   457
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   458
    if distro[0].http_proxy is not None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   459
        DC_LOGGER.debug("Setting http_proxy to %s" % distro[0].http_proxy)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   460
        set_http_proxy(distro[0].http_proxy)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   461
    else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   462
        DC_LOGGER.debug("No http_proxy specified in the manifest")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   463
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   464
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   465
def list_checkpoints(DC_LOGGER):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   466
    """ List the checkpoints listed in the manifest
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   467
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   468
    eng = InstallEngine.get_instance()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   469
    # register each checkpoint listed in the execution section
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   470
    registered_checkpoints = register_checkpoints(DC_LOGGER)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   471
    resumable_checkpoints = None
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   472
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   473
    try:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   474
        resumable_checkpoints = eng.get_resumable_checkpoints()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   475
    except (NoDatasetError, FileNotFoundError) as err:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   476
        # the build dataset is probably a virgin dataset
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   477
        DC_LOGGER.debug("No checkpoints are resumable: %s" % err)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   478
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   479
    DC_LOGGER.info("Checkpoint           Resumable Description")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   480
    DC_LOGGER.info("----------           --------- -----------")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   481
    for (name, desc) in registered_checkpoints:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   482
        if resumable_checkpoints is not None and \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   483
            name in resumable_checkpoints:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   484
            DC_LOGGER.info("%-20s%6s     %-20s" % (name, "X", desc))
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   485
        else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   486
            DC_LOGGER.info("%-20s%6s     %-20s" % (name, " ", desc))
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   487
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   488
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   489
def is_root_pool(pool_name):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   490
    """ function to determine if a zpool is the boot pool
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   491
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   492
    cmd = ["/usr/sbin/zpool", "get", "bootfs", pool_name]
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   493
    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   494
    outs, _none = p.communicate()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   495
    # if the pool is the boot pool, the output looks like
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   496
    # NAME   PROPERTY  VALUE                SOURCE
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   497
    # rpool  bootfs    rpool/ROOT/dataset   local
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   498
    # if the pool is NOT the boot pool, the VALUE will be a hypen (-)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   499
    for line in outs.splitlines():
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   500
        if line.startswith(pool_name):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   501
            if line.split()[2] != "-":
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   502
                return True
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   503
    return False
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   504
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   505
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   506
def update_doc_paths(build_data_mp):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   507
    """ function to replace placeholder strings in the DOC with actual paths
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   508
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   509
    build_data_mp - mountpoint of the build_data dataset
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   510
    """
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   511
    eng = InstallEngine.get_instance()
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   512
    doc = eng.data_object_cache
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   513
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   514
    # find all of the Software nodes
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   515
    software_list = doc.volatile.get_descendants(class_type=Software)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   516
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   517
    # iterate over each node, looking for Dir and/or Image nodes
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   518
    for software_node in software_list:
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   519
        for dir_node in software_node.get_descendants(class_type=Dir):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   520
            path = dir_node.dir_path
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   521
            path = path.replace("{BUILD_DATA}", build_data_mp)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   522
            path = path.replace("{BOOT_ARCHIVE}",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   523
               os.path.join(build_data_mp, "boot_archive"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   524
            path = path.replace("{PKG_IMAGE_PATH}",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   525
               os.path.join(build_data_mp, "pkg_image"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   526
            dir_node.dir_path = path
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   527
        for image_node in software_node.get_descendants(class_type=Image):
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   528
            path = image_node.img_root
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   529
            path = path.replace("{BUILD_DATA}", build_data_mp)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   530
            path = path.replace("{BOOT_ARCHIVE}",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   531
               os.path.join(build_data_mp, "boot_archive"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   532
            path = path.replace("{PKG_IMAGE_PATH}",
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   533
               os.path.join(build_data_mp, "pkg_image"))
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   534
            image_node.img_root = path
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   535
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   536
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   537
def main():
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   538
    """ primary execution function for distro_const
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   539
    """
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   540
    # clear the error service to be sure that we start with a clean slate
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   541
    errsvc.clear_error_list()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   542
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   543
    options, args = parse_args()
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   544
    manifest = args[-1]
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   545
    pause_checkpoint = None
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   546
    resume_checkpoint = None
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   547
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   548
    verbose = options.verbose
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   549
    list_cps = options.list_checkpoints
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   550
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   551
    try:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   552
        # We initialize the Engine with stop_on_error set so that if there are
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   553
        # errors during manifest parsing, the processing stops
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   554
        eng = InstallEngine(debug=False, stop_on_error=True)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   555
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   556
        global DC_LOGGER
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   557
        DC_LOGGER = logging.getLogger(INSTALL_LOGGER_NAME)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   558
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   559
        # set the logfile name
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   560
        log_name = "log.%s" % time.strftime("%Y-%m-%d.%H:%M")
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   561
        detail_log_name = "detail-%s" % log_name
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   562
        simple_log_name = "simple-%s" % log_name
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   563
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   564
        # create an additional FileHandler for a simple log
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   565
        base, logfile = os.path.split(DEFAULTLOG)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   566
        simple_logname = os.path.join(base, "simple-" + logfile)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   567
        simple_fh = FileHandler(simple_logname)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   568
        simple_fh.setLevel(logging.INFO)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   569
        DC_LOGGER.addHandler(simple_fh)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   570
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   571
        if options.resume_checkpoint:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   572
            resume_checkpoint = options.resume_checkpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   573
            DC_LOGGER.info("distro_const will resume from:  " + \
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   574
                           resume_checkpoint)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   575
        if options.pause_checkpoint:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   576
            pause_checkpoint = options.pause_checkpoint
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   577
            DC_LOGGER.info("distro_const will pause at:  " + pause_checkpoint)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   578
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   579
        # create a simple StreamHandler to output messages to the screen
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   580
        set_stream_handler(DC_LOGGER, list_cps, verbose)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   581
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   582
        base_dataset = None
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   583
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   584
        parse_manifest(manifest)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   585
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   586
        # get a reference to the data object cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   587
        doc = eng.data_object_cache
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   588
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   589
        # validate the target section of the manifest
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   590
        zpool_name, base_dataset, base_action, base_dataset_mp = \
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   591
            validate_target()
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   592
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   593
        if list_cps:
968
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   594
            # set the execute flag of setup_build_dataset to 'False'
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   595
            # to prevent any actions from occuring. The TI checkpoint
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   596
            # needs to be registered with the engine for list_checkpoints
196eafb14485 7008402 fix for 7006443 broke list_checkpoints
Alok Aggarwal <Alok.Aggarwal@Sun.COM>
parents: 967
diff changeset
   597
            # to work correctly.
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   598
            setup_build_dataset(zpool_name, base_dataset, base_action,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   599
                base_dataset_mp, resume_checkpoint, execute=False)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   600
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   601
            # set the InstallEngine.dataset property to enable snapshots
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   602
            eng.dataset = os.path.join(zpool_name, base_dataset, "build_data")
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   603
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   604
            list_checkpoints(DC_LOGGER)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   605
        else:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   606
            (base_dataset_mp, build_data_mp, logs_mp, media_mp) = \
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   607
                setup_build_dataset(zpool_name, base_dataset, base_action,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   608
                    base_dataset_mp, resume_checkpoint)
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   609
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   610
            # update the DOC with actual directory values
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   611
            update_doc_paths(build_data_mp)
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   612
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   613
            # lock the dataset
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   614
            with Lockfile(os.path.join(base_dataset_mp, DC_LOCKFILE)):
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   615
                # output the log file path to the screen and transfer the logs
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   616
                new_detaillog = os.path.join(logs_mp, detail_log_name)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   617
                new_simplelog = os.path.join(logs_mp, simple_log_name)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   618
                DC_LOGGER.info("Simple log: %s" % new_simplelog)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   619
                DC_LOGGER.info("Detail Log: %s" % new_detaillog)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   620
                DC_LOGGER.transfer_log(destination=new_detaillog)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   621
                simple_fh.transfer_log(destination=new_simplelog)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   622
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   623
                # set the http_proxy if one is specified in the manifest
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   624
                dc_set_http_proxy(DC_LOGGER)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   625
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   626
                # reset the InstallEngine.dataset property to enable snapshots
1070
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   627
                eng.dataset = os.path.join(zpool_name, base_dataset,
ef77609251f5 7021591 provide an implementation of TI/TD based on CUD
Drew Fisher <drew.fisher@oracle.com>
parents: 1047
diff changeset
   628
                                           "build_data")
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   629
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   630
                # register each checkpoint listed in the execution section
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   631
                registered_checkpoints = register_checkpoints(DC_LOGGER)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   632
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   633
                # now populate the DOC with the common information needed
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   634
                # by the various checkpoints -- pkg_img_path, etc
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   635
                doc_dict = {"pkg_img_path": os.path.join(build_data_mp,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   636
                                                         "pkg_image"),
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   637
                            "ba_build": os.path.join(build_data_mp,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   638
                                                     "boot_archive"),
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   639
                            "tmp_dir": os.path.join(build_data_mp, "tmp"),
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   640
                            "media_dir": media_mp}
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   641
                doc.volatile.insert_children(DataObjectDict(DC_LABEL, doc_dict,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   642
                                                            generate_xml=True))
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   643
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   644
                # if we're trying to pause at the very first checkpoint,
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   645
                # there's nothing to execute, so return 0
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   646
                if pause_checkpoint == registered_checkpoints[0][0]:
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   647
                    return 0
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   648
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   649
                execute_checkpoint(new_detaillog, resume_checkpoint,
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   650
                    pause_checkpoint)
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   651
    # catch any errors and log them.
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   652
    except BaseException as msg:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   653
        if DC_LOGGER is not None:
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   654
            DC_LOGGER.exception(msg)
960
0b70d3926a5a 7006443 transfer-ips-install checkpoint created image in wrong location
Drew Fisher <Drew.Fisher@Sun.COM>
parents: 958
diff changeset
   655
        else:
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   656
            # DC_LOGGER hasn't even been setup and we ran into an error
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   657
            print msg
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   658
        return 1
1077
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   659
    finally:
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   660
        if DC_LOGGER is not None:
99506d2f9cf7 7006574 DC build should complain if "none" is not a valid option for LiveCDPkgImgMod
Drew Fisher <drew.fisher@oracle.com>
parents: 1070
diff changeset
   661
            DC_LOGGER.close()
958
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   662
552c24933bed 7000990 The logging module needs a transfer_log method for the FileHandler class
Alok Aggarwal <alok.aggarwal@oracle.com>
parents: 947
diff changeset
   663
    return 0