Esempio n. 1
0
def main():
    # Test that virutalenv is setup
    if not os.environ.get('VIRTUAL_ENV'):
        print "Warning: VIRTUAL_ENV is not set!"
        print "Running from /opt/himlarcli"

    # Test logging config
    log_config_path = utils.get_abs_path('logging.yaml')
    if not os.path.isfile(log_config_path):
        print "Could not load logging config from %s" % log_config_path
        sys.exit(1)

    # Config file test
    config_path = '/etc/himlarcli/config.ini'
    if os.path.isfile(config_path):
        config_file(config_path)
    else:
        print "Warning: No default config file found at %s" % config_path

    # Test that requirements.txt modules are installed
    modules_file = utils.get_abs_path('tests/modules.txt')
    with open(modules_file) as f:
        modules = f.read().splitlines()
    try:
        map(__import__, modules)
    except ImportError as e:
        print e
        print "You should most likely run this in a virutalenv!"
        print "Workaround is to run /opt/himlarcli/bin/python <script>"
        sys.exit(1)
Esempio n. 2
0
def main():
    # Test that virutalenv is setup
    if not os.environ.get('VIRTUAL_ENV'):
        print "Warning: VIRTUAL_ENV is not set!"
        print "Running from /opt/himlarcli"

    # Test logging config
    log_config_path = utils.get_abs_path('logging.yaml')
    if not os.path.isfile(log_config_path):
        print "Could not load logging config from %s" % log_config_path
        sys.exit(1)

    # Config file test
    config_path = '/etc/himlarcli/config.ini'
    if os.path.isfile(config_path):
        config_file(config_path)
    else:
        print "Warning: No default config file found at %s" % config_path

    # Test that requirements.txt modules are installed
    modules_file = utils.get_abs_path('tests/modules.txt')
    with open(modules_file) as f:
        modules = f.read().splitlines()
    try:
        map(__import__, modules)
    except ImportError as e:
        print e
        print "You should most likely run this in a virutalenv!"
        print "Workaround is to run /opt/himlarcli/bin/python <script>"
        sys.exit(1)
Esempio n. 3
0
 def load_config(self, config_path):
     """ The config file will be loaded from the path given with the -c
         option path when running the script. If no -c option given it will
         also look for config.ini in:
             - local himlarcli root
             - /etc/himlarcli/
         If no config is found it will exit.
     """
     if config_path and not os.path.isfile(config_path):
         self.log_error("Could not find config file: {}".format(config_path), 1)
     elif not config_path:
         self.config_path = None
         local_config = utils.get_abs_path('config.ini')
         etc_config = '/etc/himlarcli/config.ini'
         if os.path.isfile(local_config):
             self.config_path = local_config
         else:
             if os.path.isfile(etc_config):
                 self.config_path = etc_config
         if not self.config_path:
             msg = "Config file not found in default locations:\n  {}\n  {}"
             self.log_error(msg.format(local_config, etc_config), 1)
     else:
         self.config_path = config_path
     return utils.get_config(self.config_path)
Esempio n. 4
0
def config_file(config_path):
    config_template = utils.get_abs_path('tests/config.yaml')
    config = utils.get_config(config_path)
    with open(config_template) as template:
        try:
            tests = yaml.full_load(template)
        except yaml.YAMLError as e:
            print e
    for section, options in tests.iteritems():
        if not config.has_section(section):
            print "Missing section [%s]" % section
            sys.exit(1)
        for i in options:
            if not config.has_option(section, i):
                print "Missing option %s in section [%s]" % (i, section)
                sys.exit(1)
Esempio n. 5
0
def config_file(config_path):
    config_template = utils.get_abs_path('tests/config.yaml')
    config = utils.get_config(config_path)
    with open(config_template) as template:
        try:
            tests = yaml.load(template)
        except yaml.YAMLError as e:
            print e
    for section, options in tests.iteritems():
        if not config.has_section(section):
            print "Missing section [%s]" % section
            sys.exit(1)
        for i in options:
            if not config.has_option(section, i):
                print "Missing option %s in section [%s]" % (i,section)
                sys.exit(1)
Esempio n. 6
0
def download_and_check(image):
    source = himutils.get_abs_path('%s' % image['latest'])
    url = '%s%s' % (image['url'], image['latest'])
    # Do not redownload
    if not os.path.isfile(source):
        (filename, headers) = urllib.urlretrieve(url, source)
        if int(headers['content-length']) < 1000:
            logger.debug("=> file is too small: %s" % url)
            os.remove(source)
            return None
    checksum = himutils.checksum_file(source, image['checksum'])
    checksum_url = "%s%s" % (image['url'], image['checksum_file'])
    response = urllib2.urlopen(checksum_url)
    checksum_all = response.read()
    if checksum in checksum_all:
        logger.debug("=> checksum ok: %s" % checksum)
        return source
    else:
        return None