Exemplo n.º 1
0
 def test__set_compute_flavors(self, mock_nova):
     mock_novaclient = mock.MagicMock()
     mock_novaclient.flavors.list.return_value = [
         fakes.FakeFlavor(id="id1"), fakes.FakeFlavor(id="id2")]
     mock_nova.Client.return_value = mock_novaclient
     self.conf_generator._set_compute_flavors()
     expected = ("id1", "id2")
     results = (self.conf_generator.conf.get("compute", "flavor_ref"),
                self.conf_generator.conf.get("compute", "flavor_ref_alt"))
     self.assertEqual(sorted(expected), sorted(results))
Exemplo n.º 2
0
 def test__set_compute_flavors(self):
     mock_novaclient = mock.MagicMock()
     mock_novaclient.flavors.list.return_value = [
         fakes.FakeFlavor(id="id1"), fakes.FakeFlavor(id="id2")]
     mock_nova = mock.MagicMock()
     mock_nova.client.Client.return_value = mock_novaclient
     with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
         self.conf_generator._set_compute_flavors()
         expected = ("id1", "id2")
         results = (self.conf_generator.conf.get("compute", "flavor_ref"),
                    self.conf_generator.conf.get("compute",
                                                 "flavor_ref_alt"))
         self.assertEqual(sorted(expected), sorted(results))
Exemplo n.º 3
0
    def test__create_flavor(self):
        client = self.context.clients.nova()
        client.flavors.create.side_effect = [fakes.FakeFlavor(id="id1")]

        flavor = self.context._create_flavor(64)
        self.assertEqual("id1", flavor.id)
        self.assertEqual("id1", self.context._created_flavors[0].id)
Exemplo n.º 4
0
    def test__cleanup_flavors(self):
        self.context._created_flavors = [
            fakes.FakeFlavor(id="id1"),
            fakes.FakeFlavor(id="id2")
        ]

        self.context.conf.set("compute", "flavor_ref", "id1")
        self.context.conf.set("compute", "flavor_ref_alt", "id2")

        self.context._cleanup_flavors()
        client = self.context.clients.nova()
        self.assertEqual(client.flavors.delete.call_count, 2)

        self.assertEqual("", self.context.conf.get("compute", "flavor_ref"))
        self.assertEqual("", self.context.conf.get("compute",
                                                   "flavor_ref_alt"))
Exemplo n.º 5
0
    def test__discover_or_create_flavor(self):
        client = self.context.clients.nova()
        client.flavors.list.return_value = []
        client.flavors.create.side_effect = [fakes.FakeFlavor(id="id1")]

        flavor = self.context._discover_or_create_flavor(64)
        self.assertEqual("id1", flavor.id)
        self.assertEqual("id1", self.context._created_flavors[0].id)
Exemplo n.º 6
0
    def test__discover_or_create_flavor_when_flavor_exists(self):
        client = self.context.clients.nova()
        client.flavors.list.return_value = [fakes.FakeFlavor(id="id1", ram=64,
                                                             vcpus=1, disk=0)]

        flavor = self.context._discover_or_create_flavor(64)
        self.assertEqual("id1", flavor.id)
        self.assertEqual(0, len(self.context._created_flavors))
Exemplo n.º 7
0
    def test__create_tempest_roles(self):
        role1 = CONF.role.swift_operator_role
        role2 = CONF.role.swift_reseller_admin_role
        role3 = CONF.role.heat_stack_owner_role
        role4 = CONF.role.heat_stack_user_role

        client = self.context.clients.verified_keystone()
        client.roles.list.return_value = [fakes.FakeRole(name=role1),
                                          fakes.FakeRole(name=role2)]
        client.roles.create.side_effect = [fakes.FakeFlavor(name=role3),
                                           fakes.FakeFlavor(name=role4)]

        self.context._create_tempest_roles()
        self.assertEqual(client.roles.create.call_count, 2)

        created_roles = [role.name for role in self.context._created_roles]
        self.assertIn(role3, created_roles)
        self.assertIn(role4, created_roles)
 def test__configure_option_flavor(self):
     mock_novaclient = mock.MagicMock()
     mock_novaclient.flavors.create.side_effect = [
         fakes.FakeFlavor(id="id1"), fakes.FakeFlavor(id="id2")]
     mock_nova = mock.MagicMock()
     mock_nova.client.Client.return_value = mock_novaclient
     self.context.conf.set("compute", "flavor_ref", "")
     self.context.conf.set("compute", "flavor_ref_alt", "")
     with mock.patch.dict("sys.modules", {"novaclient": mock_nova}):
         self.context._configure_option("flavor_ref",
                                        mock_novaclient.flavors.create, 64)
         self.context._configure_option("flavor_ref_alt",
                                        mock_novaclient.flavors.create, 128)
         self.assertEqual(mock_novaclient.flavors.create.call_count, 2)
         expected = ("id1", "id2")
         results = (self.context.conf.get("compute", "flavor_ref"),
                    self.context.conf.get("compute", "flavor_ref_alt"))
         self.assertEqual(sorted(expected), sorted(results))
Exemplo n.º 9
0
    def test__configure_option(self):
        create_method = mock.MagicMock()
        create_method.side_effect = [fakes.FakeFlavor(id="id1")]

        self.context.conf.set("compute", "flavor_ref", "")
        self.context._configure_option("flavor_ref", create_method, 64)
        self.assertEqual(create_method.call_count, 1)

        result = self.context.conf.get("compute", "flavor_ref")
        self.assertEqual("id1", result)
Exemplo n.º 10
0
    def test__configure_option(self):
        helper_method = mock.MagicMock()
        helper_method.side_effect = [fakes.FakeFlavor(id="id1")]

        self.context.conf.set("compute", "flavor_ref", "")
        self.context._configure_option("compute", "flavor_ref",
                                       helper_method=helper_method, flv_ram=64)
        self.assertEqual(1, helper_method.call_count)

        result = self.context.conf.get("compute", "flavor_ref")
        self.assertEqual("id1", result)
Exemplo n.º 11
0
    def test_boot_and_show_server(self):
        server = fakes.FakeServer()
        image = fakes.FakeImage()
        flavor = fakes.FakeFlavor()

        scenario = servers.NovaServers(self.context)
        scenario._boot_server = mock.MagicMock(return_value=server)
        scenario._show_server = mock.MagicMock()

        scenario.boot_and_show_server(image, flavor, fakearg="fakearg")

        scenario._boot_server.assert_called_once_with(image, flavor,
                                                      fakearg="fakearg")
        scenario._show_server.assert_called_once_with(server)
Exemplo n.º 12
0
    def test_boot_server_and_list_interfaces(self):
        server = fakes.FakeServer()
        image = fakes.FakeImage()
        flavor = fakes.FakeFlavor()

        scenario = servers.BootServerAndListInterfaces(self.context)
        scenario._boot_server = mock.MagicMock(return_value=server)
        scenario._list_interfaces = mock.MagicMock()

        scenario.run(image, flavor, fakearg="fakearg")

        scenario._boot_server.assert_called_once_with(image, flavor,
                                                      fakearg="fakearg")
        scenario._list_interfaces.assert_called_once_with(server)
Exemplo n.º 13
0
    def test_boot_and_get_console_server(self, length):
        server = fakes.FakeServer()
        image = fakes.FakeImage()
        flavor = fakes.FakeFlavor()
        kwargs = {"fakearg": "fakearg"}

        scenario = servers.BootAndGetConsoleOutput(self.context)
        scenario._boot_server = mock.MagicMock(return_value=server)
        scenario._get_server_console_output = mock.MagicMock()

        scenario.run(image, flavor, length, **kwargs)

        scenario._boot_server.assert_called_once_with(image, flavor, **kwargs)
        scenario._get_server_console_output.assert_called_once_with(
            server, length)
Exemplo n.º 14
0
    def test_boot_and_get_console_url(self):
        server = fakes.FakeServer()
        image = fakes.FakeImage()
        flavor = fakes.FakeFlavor()
        kwargs = {"fakearg": "fakearg"}

        scenario = servers.BootAndGetConsoleUrl(self.context)
        scenario._boot_server = mock.MagicMock(return_value=server)
        scenario._get_console_url_server = mock.MagicMock()

        scenario.run(image, flavor, console_type="novnc", **kwargs)

        scenario._boot_server.assert_called_once_with(image, flavor, **kwargs)
        scenario._get_console_url_server.assert_called_once_with(
            server, "novnc")
Exemplo n.º 15
0
    def test_boot_lock_unlock_and_delete(self):
        server = fakes.FakeServer()
        image = fakes.FakeImage()
        flavor = fakes.FakeFlavor()

        scenario = servers.NovaServers(self.context)
        scenario._boot_server = mock.Mock(return_value=server)
        scenario._lock_server = mock.Mock(side_effect=lambda s: s.lock())
        scenario._unlock_server = mock.Mock(side_effect=lambda s: s.unlock())
        scenario._delete_server = mock.Mock(
            side_effect=lambda s, **kwargs:
                self.assertFalse(getattr(s, "OS-EXT-STS:locked", False)))

        scenario.boot_lock_unlock_and_delete(image, flavor, fakearg="fakearg")

        scenario._boot_server.assert_called_once_with(image, flavor,
                                                      fakearg="fakearg")
        scenario._lock_server.assert_called_once_with(server)
        scenario._unlock_server.assert_called_once_with(server)
        scenario._delete_server.assert_called_once_with(server, force=False)