def test_generate_shell_script(self):
        args = {
            'run_id': 'custom-image-my-image-20190611-160823',
            'family': 'debian9',
            'image_name': 'my-image',
            'customization_script': '/tmp/my-script.sh',
            'metadata': 'key1=value1,key2=value2',
            'extra_sources': {
                "extra_src.txt": "/path/to/extra.txt"
            },
            'machine_type': 'n1-standard-2',
            'disk_size': 40,
            'accelerator': 'type=nvidia-tesla-v100,count=2',
            'gcs_bucket': 'gs://my-bucket',
            'network': 'my-network',
            'subnetwork': 'my-subnet',
            'no_external_ip': True,
            'zone': 'us-west1-a',
            'dataproc_base_image':
            'projects/cloud-dataproc/global/images/dataproc-1-4-deb9-20190510-000000-rc01',
            'service_account': 'my-service-account',
            'oauth': '',
            'project_id': 'my-project',
            'storage_location': 'us-east1',
            'shutdown_timer_in_sec': 500
        }

        script = shell_script_generator.Generator().generate(args)

        self.assertEqual(script, _expected_script)
예제 #2
0
def create(args):
    """Creates a custom image with generated Shell script."""

    # Generate Shell script.
    _LOG.info("Generating Shell script...")
    script = shell_script_generator.Generator().generate(vars(args))
    _LOG.info("#" * 60)
    _LOG.info(script)
    _LOG.info("#" * 60)
    _LOG.info("Successfully generated Shell script...")

    # Run the script to build custom image.
    if not args.dry_run:
        _LOG.info("Creating custom image...")
        shell_script_executor.run(script)
        _LOG.info("Successfully created custom image...")
    else:
        _LOG.info("Skip creating custom image (dry run).")
예제 #3
0
    def test_generate_shell_script(self):
        args = {
            'run_id': 'custom-image-my-image-20190611-160823',
            'family': 'debian9',
            'image_name': 'my-image',
            'customization_script': '/tmp/my-script.sh',
            'machine_type': 'n1-standard-2',
            'disk_size': 40,
            'gcs_bucket': 'gs://my-bucket',
            'network': 'my-network',
            'subnetwork': 'my-subnet',
            'no_external_ip': True,
            'zone': 'us-west1-a',
            'dataproc_base_image':
            'projects/cloud-dataproc/global/images/dataproc-1-4-deb9-20190510-000000-rc01',
            'service_account': 'my-service-account',
            'oauth': '',
            'project_id': 'my-project',
            'shutdown_timer_in_sec': 500
        }

        script = shell_script_generator.Generator().generate(args)

        self.assertEqual(script, _expected_script)