示例#1
0
def main(args):
    """Parsing command line options/argument for custom module"""
    if args:
        # Manage "verbose" and "quiet" options
        if args.verbose == 0:
            logging.basicConfig(level=logging.WARNING)
        elif args.verbose == 1:
            logging.basicConfig(level=logging.INFO)
        elif args.verbose >= 2:
            logging.basicConfig(level=logging.DEBUG)
        elif args.quiet:
            logging.basicConfig(level=logging.NOTSET)

        # Manage "config-file" options
        conf = load_conf(args.config_file)  # Manage None conf
        custom = Custom(conf=conf)

        # Manage "list", "status", ...
        if args.list:  # List custom iso/image status
            result = custom.list()
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.status:  # Get status of one custom iso
            result = custom.status(args.status)
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.status_all:  # Get status of all custom iso
            result = custom.status_all()
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.create:  # Create one custom iso/image
            custom.create(args.create)
        elif args.remove:  # Remove one customiso/image
            custom.remove(args.remove)
        elif args.remove_all:  # Remove all custom iso/image
            custom.remove_all()
        else:
            parser.print_help()
示例#2
0
def test_status_all(custom_config):
    with requests_mock.Mocker() as m:
        m.head('https://test.com/test_2.iso')

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        result = download.status_all()

        expected = {
            "test_0.iso": {
                "is_url_exist": False,
                "is_downloaded": False
            },
            "test_1.iso": {
                "is_url_exist": False,
                "is_downloaded": True,
                "is_hash_valid": False
            },
            "test_2.iso": {
                "is_url_exist": True,
                "is_downloaded": True,
                "is_hash_valid": True
            },
            "test_3.iso": {
                "is_url_exist": False,
                "is_downloaded": False
            }
        }
        assert result == expected
示例#3
0
def main(args):
    """Parsing comnand line options/arguments"""
    if args:

        # Manage "verbose" and "quiet" options
        if args.verbose == 0:
            logging.basicConfig(level=logging.WARNING)
        elif args.verbose == 1:
            logging.basicConfig(level=logging.INFO)
        elif args.verbose >= 2:
            logging.basicConfig(level=logging.DEBUG)
        elif args.quiet:
            logging.basicConfig(level=logging.NOTSET)

        # Manage "config-file" options
        conf = load_conf(args.config_file)  # Manage None conf
        virtualbox = Virtualbox(conf=conf)

        # Manage "list", "create", "run" and "delete" options
        if args.list:             # List custom iso/image status
            result = virtualbox.list_vms()
            print(json.dumps(result, indent=4))
        elif args.list_ostypes:
            result = virtualbox.list_ostypes()
            # print(json.dumps(result, indent=4))
            print(json.dumps(sorted(list(result.keys())), indent=4))
        elif args.create:         # Create one VM
            virtualbox.create(args.create)
        elif args.run:            # Run one existing VM
            virtualbox.run(args.run)
        elif args.remove:         # Remoce one existing VM
            virtualbox.remove(args.remove)
示例#4
0
def test_create_and_remove(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    virtualbox = Virtualbox(conf=conf)

    virtualbox.create('test_myhostname')

    virtualbox.remove('test_myhostname')
示例#5
0
def test_get_machine_folder(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    virtualbox = Virtualbox(conf=conf)
    result = virtualbox.get_machine_folder()

    assert result
    assert isinstance(result, str)
示例#6
0
def test_download_all(custom_config, file_to_download):
    with requests_mock.Mocker() as m:
        with open(file_to_download) as file:
            m.get('https://test.com/test_0.iso',
                  headers={'content-length': '29'},
                  body=file)
            m.get('https://test.com/test_1.iso',
                  headers={'content-length': '29'},
                  body=file)
            m.get('https://test.com/test_2.iso',
                  headers={'content-length': '29'},
                  body=file)
            m.get('https://test.com/test_3.iso',
                  headers={'content-length': '29'},
                  body=file)

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        download.download_all()

        result = True
        for file_name in custom_config['download'].keys():
            file_path = os.path.join(custom_config['general']['dir_input'],
                                     file_name)
            if not os.path.isfile(file_path):
                result = False
        assert result
示例#7
0
    def __init__(self, conf_file=None):
        """Init by loading main configuration file"""
        self.conf = load_conf(conf_file)

        self.download = Download(conf=self.conf)
        self.custom = Custom(conf=self.conf)
        self.vitualbox = Virtualbox(conf=self.conf)
示例#8
0
def test_remove_iso_already_downloaded(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    download = Download(conf=conf)
    result = download.remove('test_2.iso')

    result = os.path.isfile(
        os.path.join(custom_config['general']['dir_input'], 'test_2.iso'))

    assert not result
示例#9
0
def test_list_with_custom_configuration(custom_config):
    # Run test
    conf = load_conf(confDict=custom_config)  # Custom configuration
    download = Download(conf=conf)
    result = download.list()

    # Compare result
    excepted = ["test_0.iso", "test_1.iso", "test_2.iso", "test_3.iso"]
    assert result.sort() == excepted.sort()
示例#10
0
def test_list_with_custom_configuration(custom_config):
    # Run test
    conf = load_conf(confDict=custom_config)  # Custom configuration
    custom = Custom(conf=conf)
    result = custom.list()

    # Compare result
    excepted = ['test_custom_0.iso']
    assert result.sort() == excepted.sort()
示例#11
0
def test_status_iso_not_create(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    custom = Custom(conf=conf)
    result = custom.status('test_custom_0.iso')

    expected = {
        'is_exist': False
    }

    assert result == expected
示例#12
0
def test_status_iso_not_downloaded(custom_config):
    with requests_mock.Mocker() as m:
        m.head('https://test.com/test_0.iso')

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        result = download.status('test_0.iso')

        expected = {'is_url_exist': True, 'is_downloaded': False}

        assert result == expected
示例#13
0
def test_status_http_exception(custom_config):
    with requests_mock.Mocker() as m:
        m.register_uri('HEAD', 'https://test.com/test_0.iso', exc=Exception)

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        result = download.status('test_0.iso')

        expected = {'is_url_exist': False, 'is_downloaded': False}

        assert result == expected
示例#14
0
def test_remove_all_iso(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    download = Download(conf=conf)
    result = download.remove_all()

    result = True
    for file_name in custom_config['download'].keys():
        file_path = os.path.join(custom_config['general']['dir_input'],
                                 file_name)
        if os.path.isfile(file_path):
            result = False

    assert result
示例#15
0
def test_download_iso_not_downloaded(custom_config, file_to_download):
    with requests_mock.Mocker() as m:
        with open(file_to_download) as file:
            m.get('https://test.com/test_3.iso',
                  headers={'content-length': '29'},
                  body=file)

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        download.download('test_3.iso')

        result = os.path.isfile(
            os.path.join(custom_config['general']['dir_input'], 'test_3.iso'))
        assert result
示例#16
0
def test_download_iso_already_downloaded(custom_config, file_to_download):
    iso_path = os.path.join(custom_config['general']['dir_input'],
                            'test_2.iso')
    init_timestamp = os.path.getmtime(iso_path)
    print(init_timestamp)
    with requests_mock.Mocker() as m:
        with open(file_to_download) as file:
            m.get('https://test.com/test_2.iso',
                  headers={'content-length': '29'},
                  body=file)

        conf = load_conf(confDict=custom_config)  # Custom configuration
        download = Download(conf=conf)
        download.download('test_2.iso')

        result = os.path.getmtime(iso_path)
        expected = init_timestamp
        assert result == expected
示例#17
0
def main(args):
    """Parsing comnand line options/arguments"""

    if args:
        # Manage "verbose" and "quiet" options
        if args.verbose == 0:
            logging.basicConfig(level=logging.WARNING)
        elif args.verbose == 1:
            logging.basicConfig(level=logging.INFO)
        elif args.verbose >= 2:
            logging.basicConfig(level=logging.DEBUG)
        elif args.quiet:
            logging.basicConfig(level=logging.NOTSET)

        # Manage "config-file" options
        conf = load_conf(args.config_file)  # Manage None conf
        download = Download(conf=conf)

        # Manage options "list", "download", "download-all",
        #   "remove" and "remove-all"
        if args.list:  # List iso/image status
            result = download.list()
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.status:  # Get status of one iso
            result = download.status(args.status)
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.status_all:  # Get status of all iso
            result = download.status_all()
            print(json.dumps(result, indent=4, sort_keys=True))
        elif args.download:  # Download one iso/image
            download.download(args.download)
        elif args.download_all:  # Download all iso/image
            download.download_all()
        elif args.remove:  # Remove one iso/image
            download.remove(args.remove)
        elif args.remove_all:  # Remove all iso/image
            download.remove_all()
        else:
            parser.print_help()
示例#18
0
def test_list_vms_with_custom_configuration(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    virtualbox = Virtualbox(conf=conf)
    result = virtualbox.list_vms()

    assert isinstance(result, list)
示例#19
0
def test_list_ostypes(custom_config):
    conf = load_conf(confDict=custom_config)  # Custom configuration
    virtualbox = Virtualbox(conf=conf)
    result = virtualbox.list_ostypes()

    assert isinstance(result, dict)