Example #1
0
    def create_one_image(self, user, **kwargs):
        """Create one image for the user."""

        clients = osclients.Clients(user["credential"])

        image_id = types.GlanceImage(self.context).pre_process(
            resource_spec=self.config["image"], config={})
        flavor_id = types.Flavor(self.context).pre_process(
            resource_spec=self.config["flavor"], config={})

        vm_scenario = vmtasks.BootRuncommandDelete(self.context,
                                                   clients=clients)

        server, fip = vm_scenario._boot_server_with_fip(
            image=image_id, flavor=flavor_id,
            floating_network=self.config.get("floating_network"),
            userdata=self.config.get("userdata"),
            key_name=user["keypair"]["name"],
            security_groups=[user["secgroup"]["name"]],
            **kwargs)

        try:
            LOG.debug("Installing tools on %r %s" % (server, fip["ip"]))
            self.customize_image(server, fip, user)

            LOG.debug("Stopping server %r" % server)
            vm_scenario._stop_server(server)

            LOG.debug("Creating snapshot for %r" % server)
            custom_image = vm_scenario._create_image(server)
        finally:
            vm_scenario._delete_server_with_fip(server, fip)

        return custom_image
Example #2
0
 def setUp(self):
     super(FlavorTestCase, self).setUp()
     self.clients = fakes.FakeClients()
     self.clients.nova().flavors._cache(
         fakes.FakeResource(name="m1.tiny", id="1"))
     self.clients.nova().flavors._cache(
         fakes.FakeResource(name="m1.nano", id="42"))
     self.clients.nova().flavors._cache(
         fakes.FakeResource(name="m1.large", id="44"))
     self.clients.nova().flavors._cache(
         fakes.FakeResource(name="m1.large", id="45"))
     self.type_cls = types.Flavor(
         context={"admin": {
             "credential": mock.Mock()
         }})
     self.type_cls._clients = self.clients
Example #3
0
    def _get_validated_flavor(self, config, clients, param_name):

        from novaclient import exceptions as nova_exc

        flavor_value = config.get("args", {}).get(param_name)
        if not flavor_value:
            self.fail("Parameter %s is not specified." % param_name)
        try:
            flavor_processor = openstack_types.Flavor(
                context={"admin": {
                    "credential": clients.credential
                }})
            flavor_id = flavor_processor.pre_process(flavor_value, config={})
            flavor = clients.nova().flavors.get(flavor=flavor_id)
            return flavor
        except (nova_exc.NotFound, exceptions.InvalidScenarioArgument):
            try:
                return self._get_flavor_from_context(config, flavor_value)
            except validation.ValidationError:
                pass
            self.fail("Flavor '%s' not found" % flavor_value)