Example #1
0
 def test__renders_with_hosts(self):
     params = make_sample_params(self, ipv6=self.ipv6)
     self.assertThat(
         params["hosts"], AfterPreprocessing(len, GreaterThanOrEqual(1))
     )
     config_output = config.get_config(self.template, **params)
     validate_dhcpd_configuration(self, config_output, self.ipv6)
     self.assertThat(
         config_output,
         ContainsAll([host["host"] for host in params["hosts"]]),
     )
     self.assertThat(
         config_output,
         ContainsAll([host["mac"] for host in params["hosts"]]),
     )
     self.assertThat(
         config_output,
         ContainsAll([host["ip"] for host in params["hosts"]]),
     )
Example #2
0
 def test_GET_returns_boot_resource(self):
     resource = factory.make_usable_boot_resource()
     response = self.client.get(get_boot_resource_uri(resource))
     self.assertEqual(http.client.OK, response.status_code)
     returned_resource = json_load_bytes(response.content)
     # The returned object contains a 'resource_uri' field.
     self.assertEqual(reverse('boot_resource_handler', args=[resource.id]),
                      returned_resource['resource_uri'])
     self.assertThat(returned_resource,
                     ContainsAll(['id', 'type', 'name', 'architecture']))
Example #3
0
 def test_compose_rootfs_over_http_ipv6(self):
     params = make_kernel_parameters(fs_host=factory.make_ipv6_address())
     self.assertThat(
         compose_kernel_command_line(params),
         ContainsAll([
             "ro",
             "root=squash:http://[%s]:5248/images/%s/%s/%s/%s/%s/squashfs" %
             (params.fs_host, params.osystem, params.arch, params.subarch,
              params.release, params.label)
         ]))
 def test_settings_contains_links_to_edit(self):
     self.client.login(user=factory.make_admin())
     keys, _ = self.make_license_keys(3)
     links = get_content_links(
         self.client.get(reverse("settings_license_keys")))
     license_key_delete_links = [
         reverse("license-key-edit", args=[key.osystem, key.distro_series])
         for key in keys
     ]
     self.assertThat(links, ContainsAll(license_key_delete_links))
Example #5
0
    def test__includes_other_class_attributes(self):
        class Example:
            alice = "is the first"
            bob = lambda self: "just bob"
            dave = property(lambda self: "or david")

        example = Example()

        self.assertThat(list(dir_instance(example)),
                        ContainsAll(["alice", "bob", "dave"]))
Example #6
0
    def test_GET_lists_users(self):
        users = [factory.make_User() for counter in range(2)]

        response = self.client.get(reverse('users_handler'))
        self.assertEqual(http.client.OK, response.status_code,
                         response.content)

        listing = json.loads(response.content.decode(settings.DEFAULT_CHARSET))
        self.assertThat([user['username'] for user in listing],
                        ContainsAll([user.username for user in users]))
Example #7
0
    def test__includes_other_class_attributes(self):
        class Example:
            alice = "is the first"
            bob = lambda self: "just bob"
            carol = classmethod(lambda cls: "carol")
            dave = property(lambda self: "dave or david")
            erin = staticmethod(lambda: "or eve?")

        self.assertThat(list(dir_class(Example)),
                        ContainsAll(["alice", "bob", "carol", "dave", "erin"]))
 def test_settings_contains_osystem_and_distro_series(self):
     self.client.login(user=factory.make_admin())
     keys, _ = self.make_license_keys(3)
     response = self.client.get(reverse("settings_license_keys"))
     os_titles = [key.osystem for key in keys]
     series_titles = [key.distro_series for key in keys]
     self.assertThat(
         response.content.decode(settings.DEFAULT_CHARSET),
         ContainsAll([title for title in os_titles + series_titles]),
     )
Example #9
0
 def test_get_reader_scenarios(self):
     # The commissioning config uses an extra PXELINUX module to auto
     # select between i386 and amd64.
     method = PXEBootMethod()
     get_ephemeral_name = self.patch(kernel_opts, "get_ephemeral_name")
     get_ephemeral_name.return_value = factory.make_name("ephemeral")
     osystem = factory.make_name('osystem')
     options = {
         "backend":
         None,
         "kernel_params":
         make_kernel_parameters(testcase=self,
                                osystem=osystem,
                                subarch="generic",
                                purpose='enlist'),
     }
     fs_host = 'http://%s:5248/images' % (convert_host_to_uri_str(
         options['kernel_params'].fs_host))
     output = method.get_reader(**options).read(10000).decode("utf-8")
     config = parse_pxe_config(output)
     # The default section is defined.
     default_section_label = config.header["DEFAULT"]
     self.assertThat(config, Contains(default_section_label))
     default_section = config[default_section_label]
     # The default section uses the ifcpu64 module, branching to the "i386"
     # or "amd64" labels accordingly.
     self.assertEqual("ifcpu64.c32", default_section["KERNEL"])
     self.assertEqual(["amd64", "--", "i386"],
                      default_section["APPEND"].split())
     # Both "i386" and "amd64" sections exist.
     self.assertThat(config, ContainsAll(("i386", "amd64")))
     # Each section defines KERNEL, INITRD, and APPEND settings.  The
     # KERNEL and INITRD ones contain paths referring to their
     # architectures.
     for section_label in ("i386", "amd64"):
         section = config[section_label]
         self.assertThat(section, ContainsAll(
             ("KERNEL", "INITRD", "APPEND")))
         contains_arch_path = StartsWith("%s/%s/%s/" %
                                         (fs_host, osystem, section_label))
         self.assertThat(section["KERNEL"], contains_arch_path)
         self.assertThat(section["INITRD"], contains_arch_path)
         self.assertIn("APPEND", section)
Example #10
0
 def test_settings_contains_names_and_content_of_scripts(self):
     self.client.login(user=factory.make_admin())
     scripts = [
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING),
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING),
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING, default=True),
     ]
     response = self.client.get(reverse("settings_scripts"))
     names = [script.name for script in scripts[:-1]]
     contents = [script.script.data for script in scripts[:-1]]
     self.assertThat(
         response.content,
         ContainsAll(
             [name.encode(settings.DEFAULT_CHARSET) for name in names]),
     )
     self.assertThat(
         response.content,
         ContainsAll([content.encode() for content in contents]),
     )
Example #11
0
 def test__renders_global_dhcp_snippets(self):
     params = make_sample_params(self, ipv6=self.ipv6)
     config_output = config.get_config(self.template, **params)
     validate_dhcpd_configuration(self, config_output, self.ipv6)
     self.assertThat(
         config_output,
         ContainsAll([
             dhcp_snippet['value']
             for dhcp_snippet in params['global_dhcp_snippets']
         ]))
Example #12
0
    def test_opencv(self):
        snap_path = self.build_snap(self.snap_content_dir)

        bin_path = os.path.join(os.path.dirname(snap_path), 'prime', 'bin',
                                'example')
        self.assertThat(bin_path, FileExists())

        interpreter = subprocess.check_output(
            ['patchelf', '--print-interpreter', bin_path]).decode()
        expected_interpreter = r'^/snap/core/current/.*'
        self.assertThat(interpreter, MatchesRegex(expected_interpreter))

        arch_triplet = snapcraft.ProjectOptions().arch_triplet

        # test $ORIGIN in action
        rpath = subprocess.check_output(
            ['patchelf', '--print-rpath', bin_path]).decode()
        expected_rpath = '$ORIGIN/../usr/lib/{}:'.format(arch_triplet)
        self.assertThat(rpath, Contains(expected_rpath))

        # test $ORIGIN applied
        ldd = subprocess.check_output(['ldd', bin_path]).decode()
        expected_opencv_path = (
            '/prime/bin/../usr/lib/{}/libopencv_core'.format(arch_triplet))
        self.assertThat(ldd, Contains(expected_opencv_path))

        self.install_snap(snap_path, 'opencv-example', '1.0', classic=True)
        if not snaps_tests.config.get('skip-install', False):
            output = self.run_command_in_snappy_testbed(
                '/snap/bin/opencv-example.example').splitlines()

            # Depending on opencv the result is now displayed differently
            # so let's do a lazy match.
            # On artful you see:
            # [  1,   3;
            #    2,   4]
            # And on others:
            # [1, 3;
            #  2, 4]
            expected_in_first_line = ['[', '1', ',', '3', ';']
            self.assertThat(output[0], ContainsAll(expected_in_first_line))
            expected_in_second_line = ['2', ',', '4', ']']
            self.assertThat(output[1], ContainsAll(expected_in_second_line))
Example #13
0
 def test__generate_pod_types_doc_generates_describes_types(self):
     pod_driver = random.choice([
         driver
         for _, driver in PodDriverRegistry
     ])
     doc = generate_pod_types_doc()
     self.assertThat(
         doc,
         ContainsAll([
             pod_driver.name,
             pod_driver.description]))
Example #14
0
 def test_settings_contains_links_to_delete_scripts(self):
     self.client.login(user=factory.make_admin())
     scripts = {
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING),
         factory.make_Script(script_type=SCRIPT_TYPE.TESTING),
         }
     links = get_content_links(self.client.get(reverse('settings_scripts')))
     script_delete_links = [
         reverse('test-script-delete', args=[script.id])
         for script in scripts]
     self.assertThat(links, ContainsAll(script_delete_links))
Example #15
0
 def test__loads_yaml_embedded_attributes(self):
     embedded_yaml = {
         'name': factory.make_name('name'),
         'title': factory.make_name('title'),
         'description': factory.make_name('description'),
         'tags': [factory.make_name('tag') for _ in range(3)],
         'script_type': factory.pick_choice(SCRIPT_TYPE_CHOICES),
         'hardware_type': factory.pick_choice(HARDWARE_TYPE_CHOICES),
         'parallel': factory.pick_choice(SCRIPT_PARALLEL_CHOICES),
         'results': ['write_speed'],
         'parameters': [{'type': 'storage'}, {'type': 'runtime'}],
         'packages': {'apt': [factory.make_name('package')]},
         'timeout': random.randint(0, 1000),
         'destructive': factory.pick_bool(),
         'may_reboot': factory.pick_bool(),
     }
     if embedded_yaml['script_type'] == SCRIPT_TYPE.COMMISSIONING:
         embedded_yaml['for_hardware'] = [
             'modalias:%s' % factory.make_name('mod_alias'),
             'pci:%04X:%04x' % (
                 random.randint(0, 9999), random.randint(0, 9999)),
             'usb:%04X:%04x' % (
                 random.randint(0, 9999), random.randint(0, 9999)),
             ]
         embedded_yaml['recommission'] = factory.pick_bool()
     script_content = factory.make_script_content(embedded_yaml)
     form = ScriptForm(data={'script': script_content})
     self.assertTrue(form.is_valid(), form.errors)
     script = form.save()
     self.assertEquals(embedded_yaml['name'], script.name)
     self.assertEquals(embedded_yaml['title'], script.title)
     self.assertEquals(embedded_yaml['description'], script.description)
     self.assertThat(script.tags, ContainsAll(embedded_yaml['tags']))
     self.assertEquals(embedded_yaml['script_type'], script.script_type)
     self.assertEquals(embedded_yaml['hardware_type'], script.hardware_type)
     self.assertEquals(embedded_yaml['parallel'], script.parallel)
     self.assertItemsEqual(embedded_yaml['results'], script.results)
     self.assertItemsEqual(embedded_yaml['parameters'], script.parameters)
     self.assertDictEqual(embedded_yaml['packages'], script.packages)
     self.assertEquals(
         timedelta(0, embedded_yaml['timeout']), script.timeout)
     self.assertEquals(embedded_yaml['destructive'], script.destructive)
     self.assertEquals(embedded_yaml['may_reboot'], script.may_reboot)
     if embedded_yaml['script_type'] == SCRIPT_TYPE.COMMISSIONING:
         self.assertItemsEqual(
             embedded_yaml['for_hardware'], script.for_hardware)
         self.assertEquals(
             embedded_yaml['recommission'], script.recommission)
     else:
         self.assertItemsEqual([], script.for_hardware)
         self.assertFalse(script.recommission)
     self.assertFalse(script.default)
     self.assertEquals(script_content, script.script.data)
Example #16
0
 def test_enlist_compose_kernel_command_line_inc_purpose_opts6(self):
     # The result of compose_kernel_command_line includes the purpose
     # options for a non "commissioning" node.
     params = self.make_kernel_parameters(
         purpose="enlist", fs_host=factory.make_ipv6_address())
     cmdline = compose_kernel_command_line(params)
     self.assertThat(
         cmdline,
         ContainsAll([
             "root=squash:http://", "overlayroot=tmpfs", "ip=off",
             "ip6=dhcp"
         ]))
Example #17
0
 def test_enlist_compose_kernel_command_line_inc_cc_datasource(self):
     # The result of compose_kernel_command_line includes the cloud-init
     # options for the datasource and cloud-config-url
     params = self.make_kernel_parameters(
         purpose="enlist", fs_host=factory.make_ipv4_address())
     cmdline = compose_kernel_command_line(params)
     self.assertThat(
         cmdline,
         ContainsAll([
             "cc:{'datasource_list': ['MAAS']}end_cc",
             "cloud-config-url=%s" % params.preseed_url
         ]))
Example #18
0
 def test_renders_node_dhcp_snippets(self):
     params = make_sample_params(self, ipv6=self.ipv6)
     config_output = config.get_config(self.template, **params)
     validate_dhcpd_configuration(self, config_output, self.ipv6)
     for host in params["hosts"]:
         self.assertThat(
             config_output,
             ContainsAll([
                 dhcp_snippet["value"]
                 for dhcp_snippet in host["dhcp_snippets"]
             ]),
         )
Example #19
0
    def test_volume_busy_error_on_busy_state(self, logger):
        """
        A ``VolumeBusy`` is raised if a volume's attachment state is "busy"
        when attempting to detach the volume. This can occur if an attempt
        is made to detach a volume that has not been unmounted.
        """
        try:
            config = get_blockdevice_config()
        except InvalidConfig as e:
            self.skipTest(str(e))

        # Create a volume
        dataset_id = uuid4()
        flocker_volume = self.api.create_volume(
            dataset_id=dataset_id,
            size=self.minimum_allocatable_size,
        )
        ec2_client = get_ec2_client_for_test(config)

        # Attach the volume.
        instance_id = self.api.compute_instance_id()
        self.api.attach_volume(flocker_volume.blockdevice_id, instance_id)

        volume = ec2_client.connection.Volume(flocker_volume.blockdevice_id)

        def clean_volume(volume):
            volume.detach_from_instance()
            _wait_for_volume_state_change(VolumeOperations.DETACH, volume)
            volume.delete()

        self.addCleanup(clean_volume, volume)

        # Artificially set the volume's attachment state to "busy", by
        # monkey-patching the EBS driver's ``_get_ebs_volume`` method.
        def busy_ebs_volume(volume_id):
            busy_volume = ec2_client.connection.Volume(volume_id)
            busy_volume.load()
            if busy_volume.attachments:
                busy_volume.attachments[0]['State'] = "busy"
            return busy_volume

        self.patch(self.api, "_get_ebs_volume", busy_ebs_volume)

        # Try to detach and get the VolumeBusy exception.
        self.assertRaises(VolumeBusy, self.api.detach_volume,
                          flocker_volume.blockdevice_id)

        expected_keys = set(["volume_id", "attachments"])
        messages = [
            message.message for message in LoggedMessage.of_type(
                logger.messages, VOLUME_BUSY_MESSAGE)
        ]
        self.assertThat(messages, AllMatch(ContainsAll(expected_keys)))
Example #20
0
 def test_xinstall_compose_kernel_command_line_inc_purpose_opts4(self):
     # The result of compose_kernel_command_line includes the purpose
     # options for a non "xinstall" node.
     params = self.make_kernel_parameters(
         purpose="xinstall", fs_host=factory.make_ipv4_address())
     cmdline = compose_kernel_command_line(params)
     self.assertThat(
         cmdline,
         ContainsAll([
             "root=squash:http://", "overlayroot=tmpfs", "ip6=off",
             "ip=::::%s:BOOTIF" % params.hostname
         ]))
Example #21
0
 def test__renders_subnet_dhcp_snippets(self):
     params = make_sample_params(self, ipv6=self.ipv6)
     config_output = config.get_config(self.template, **params)
     validate_dhcpd_configuration(self, config_output, self.ipv6)
     for shared_network in params['shared_networks']:
         for subnet in shared_network['subnets']:
             self.assertThat(
                 config_output,
                 ContainsAll([
                     dhcp_snippet['value']
                     for dhcp_snippet in subnet['dhcp_snippets']
                 ]))
Example #22
0
 def test_settings_contains_links_to_delete_scripts(self):
     self.client.login(user=factory.make_admin())
     scripts = {
         factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING),
         factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING),
     }
     links = get_content_links(self.client.get(reverse("settings_scripts")))
     script_delete_links = [
         reverse("commissioning-script-delete", args=[script.id])
         for script in scripts
     ]
     self.assertThat(links, ContainsAll(script_delete_links))
Example #23
0
    def test__update(self):
        script = factory.make_Script()
        name = factory.make_name('name')
        title = factory.make_name('title')
        description = factory.make_name('description')
        tags = [factory.make_name('tag') for _ in range(3)]
        script_type = factory.pick_choice(SCRIPT_TYPE_CHOICES)
        hardware_type = factory.pick_choice(HARDWARE_TYPE_CHOICES)
        parallel = factory.pick_choice(SCRIPT_PARALLEL_CHOICES)
        packages = {'apt': [factory.make_name('package')]}
        timeout = random.randint(0, 1000)
        destructive = factory.pick_bool()
        script_content = factory.make_script_content()
        comment = factory.make_name('comment')
        orig_script_content = script.script.data

        form = ScriptForm(data={
            'name': name,
            'title': title,
            'description': description,
            'tags': ','.join(tags),
            'type': script_type,
            'hardware_type': hardware_type,
            'parallel': parallel,
            'packages': json.dumps(packages),
            'timeout': str(timeout),
            'destructive': destructive,
            'script': script_content,
            'comment': comment,
        },
                          instance=script)
        self.assertTrue(form.is_valid(), form.errors)
        script = form.save()

        self.assertEquals(name, script.name)
        self.assertEquals(title, script.title)
        self.assertEquals(description, script.description)
        self.assertThat(script.tags, ContainsAll(tags))
        self.assertEquals(script_type, script.script_type)
        self.assertEquals(hardware_type, script.hardware_type)
        self.assertEquals(parallel, script.parallel)
        self.assertDictEqual({}, script.results)
        self.assertDictEqual({}, script.parameters)
        self.assertDictEqual(packages, script.packages)
        self.assertEquals(timedelta(0, timeout), script.timeout)
        self.assertEquals(destructive, script.destructive)
        self.assertEquals(script_content, script.script.data)
        self.assertEquals(comment, script.script.comment)
        self.assertEquals(orig_script_content,
                          script.script.previous_version.data)
        self.assertEquals(None, script.script.previous_version.comment)
        self.assertFalse(script.default)
Example #24
0
    def test_PUT(self):
        self.become_admin()
        script = factory.make_Script()
        name = factory.make_name("script")
        title = factory.make_name("title")
        description = factory.make_name("description")
        tags = [factory.make_name("tag") for _ in range(3)]
        script_type = factory.pick_choice(SCRIPT_TYPE_CHOICES)
        script_type = factory.pick_choice(SCRIPT_TYPE_CHOICES)
        hardware_type = factory.pick_choice(HARDWARE_TYPE_CHOICES)
        parallel = factory.pick_choice(SCRIPT_PARALLEL_CHOICES)
        packages = {"apt": [factory.make_name("apt_pkg")]}
        timeout = random.randint(0, 1000)
        destructive = factory.pick_bool()
        script_content = factory.make_script_content()
        comment = factory.make_name("comment")

        response = self.client.put(
            self.get_script_uri(script),
            {
                "name": name,
                "title": title,
                "description": description,
                "tags": ",".join(tags),
                "type": script_type,
                "hardware_type": hardware_type,
                "parallel": parallel,
                "packages": json.dumps(packages),
                "timeout": timeout,
                "destructive": destructive,
                "script": factory.make_file_upload(
                    content=script_content.encode()
                ),
                "comment": comment,
            },
        )
        self.assertThat(response, HasStatusCode(http.client.OK))
        script = reload_object(script)

        self.assertEquals(name, script.name)
        self.assertEquals(title, script.title)
        self.assertEquals(description, script.description)
        self.assertThat(script.tags, ContainsAll(tags))
        self.assertEquals(script_type, script.script_type)
        self.assertEquals(hardware_type, script.hardware_type)
        self.assertEquals(parallel, script.parallel)
        self.assertDictEqual(packages, script.packages)
        self.assertEquals(timeout, script.timeout.seconds)
        self.assertEquals(destructive, script.destructive)
        self.assertEquals(script_content, script.script.data)
        self.assertEquals(comment, script.script.comment)
        self.assertIsNotNone(script.script.previous_version)
Example #25
0
 def tests_yaml_tags_can_be_list_of_strings(self):
     tags = [factory.make_name("tag") for _ in range(3)]
     form = ScriptForm(
         data={
             "script":
             factory.make_script_content({
                 "name": factory.make_name("name"),
                 "tags": tags
             })
         })
     self.assertTrue(form.is_valid(), form.errors)
     script = form.save()
     self.assertThat(script.tags, ContainsAll(tags))
    def test_update_volume_metadata(self):
        # Update metadata for the volume
        metadata = {"key1": "value1", "key2": "value2", "key3": "value3"}

        update = {"key4": "value4", "key1": "value1_update"}

        # Create metadata for the volume
        resp, body = self.volumes_client.create_volume_metadata(
            self.volume_id, metadata)
        self.assertEqual(200, resp.status)
        # Get the metadata of the volume
        resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
        self.assertEqual(200, resp.status)
        self.assertThat(body.items(), ContainsAll(metadata.items()))
        # Update metadata
        resp, body = self.volumes_client.update_volume_metadata(
            self.volume_id, update)
        self.assertEqual(200, resp.status)
        # Get the metadata of the volume
        resp, body = self.volumes_client.get_volume_metadata(self.volume_id)
        self.assertEqual(200, resp.status)
        self.assertThat(body.items(), ContainsAll(update.items()))
Example #27
0
 def test_writes_dns_zone_config_with_NS_record(self):
     target_dir = patch_dns_config_path(self)
     addr_ttl = random.randint(10, 100)
     ns_host_name = factory.make_name("ns")
     dns_zone_config = DNSForwardZoneConfig(factory.make_string(),
                                            serial=random.randint(1, 100),
                                            ns_host_name=ns_host_name,
                                            ipv4_ttl=addr_ttl,
                                            ipv6_ttl=addr_ttl)
     dns_zone_config.write_config()
     self.assertThat(
         os.path.join(target_dir, 'zone.%s' % dns_zone_config.domain),
         FileContains(matcher=ContainsAll(['30 IN NS %s.' % ns_host_name])))
Example #28
0
 def tests_yaml_tags_can_be_list_of_strings(self):
     tags = [factory.make_name('tag') for _ in range(3)]
     form = ScriptForm(
         data={
             'script':
             factory.make_script_content({
                 'name': factory.make_name('name'),
                 'tags': tags,
             })
         })
     self.assertTrue(form.is_valid(), form.errors)
     script = form.save()
     self.assertThat(script.tags, ContainsAll(tags))
Example #29
0
 def test__generate_power_types_doc_generates_describes_power_type(self):
     power_driver = random.choice([
         driver for _, driver in PowerDriverRegistry
         if len(driver.settings) > 0
     ])
     doc = generate_power_types_doc()
     self.assertThat(
         doc,
         ContainsAll([
             power_driver.name, power_driver.description,
             power_driver.settings[0]['name'],
             power_driver.settings[0]['label']
         ]))
Example #30
0
    def test_update_script(self):
        load_builtin_scripts()
        update_script_values = random.choice(BUILTIN_SCRIPTS)
        script = Script.objects.get(name=update_script_values.name)

        # Fields which we can update
        orig_title = script.title
        orig_description = script.description
        orig_script_type = script.script_type
        orig_results = script.results
        orig_parameters = script.parameters

        script.title = factory.make_string()
        script.description = factory.make_string()
        script.script_type = factory.pick_choice(SCRIPT_TYPE_CHOICES)
        script.results = [factory.make_name("result")]
        script.script.parameters = {
            factory.make_name("param"): {
                "type": "storage"
            }
        }

        # Put fake old data in to simulate updating a script.
        old_script = VersionedTextFile.objects.create(
            data=factory.make_string())
        script.script = old_script

        # User changeable fields.
        user_tags = [factory.make_name("tag") for _ in range(3)]
        script.tags = copy.deepcopy(user_tags)
        user_timeout = timedelta(random.randint(0, 1000))
        script.timeout = user_timeout
        script.save()

        load_builtin_scripts()
        script = reload_object(script)

        self.assertEquals(orig_title, script.title, script.name)
        self.assertEquals(orig_description, script.description, script.name)
        self.assertEquals(orig_script_type, script.script_type, script.name)
        self.assertDictEqual(orig_results, script.results, script.name)
        self.assertDictEqual(orig_parameters, script.parameters, script.name)

        self.assertThat(script.tags, ContainsAll(user_tags))
        self.assertEquals(user_timeout, script.timeout)

        self.assertEquals(old_script, script.script.previous_version)
        self.assertEquals("Updated by maas-%s" % get_maas_version(),
                          script.script.comment)
        self.assertTrue(script.default)