예제 #1
0
def migrate_server(context, server_id):
    server = context.src_cloud.nova.servers.get(server_id)
    server_id = server.id
    flavor_id = server.flavor["id"]
    flavor_retrieve = "flavor-{}-retrieve".format(flavor_id)
    resources = []
    identity_flow = identity_tasks.migrate_server_identity(context, server.to_dict())
    resources.append(identity_flow)
    tenant = context.src_cloud.keystone.tenants.get(server.tenant_id)
    server_secgroups = server.list_security_group()
    for secgroup in server_secgroups:
        secgroup_retrieve = "secgroup-{}-retrieve".format(secgroup.id)
        if secgroup_retrieve not in context.store:
            secgroup_flow = secgroup_tasks.migrate_secgroup(context, secgroup.id, tenant.id, server.user_id)
            resources.append(secgroup_flow)
    server_nics = "server-{}-nics".format(server_id)
    nics = []
    for network_name, addresses in server.addresses.iteritems():
        for address in addresses:
            flow, nic = network_tasks.migrate_nic(context, network_name, address, tenant.id)
            if flow is not None:
                resources.append(flow)
            if nic is not None:
                nics.append(nic)
    resources.append(task_utils.Gather(name=server_nics, provides=server_nics, rebind=nics))
    if flavor_retrieve not in context.store:
        flavor_flow = flavor_tasks.migrate_flavor(context, flavor_id)
        resources.append(flavor_flow)
    add_resources, server_flow = server_tasks.reprovision_server(context, server, server_nics)
    resources += add_resources
    return resources, server_flow
예제 #2
0
    def test_migrate_server_identity(self):
        self.patchFlows()
        self.context.store = {
            "user-role-%s-%s-%s-ensure" % (self.user_id,
                                           self.roles[3].id,
                                           self.tenant_id): True,
        }

        flow = identity.migrate_server_identity(
            self.context,
            self.server_info
        )

        self.src_cloud.keystone.users.list_roles.assert_called_once_with(
            self.user_id,
            tenant=self.tenant_id
        )

        self.mock_flow.assert_called_once_with(
            "server-identity-%s" % self.server_info["id"]
        )

        # Tenant migration task created
        self.assertEqual(
            self.mock_tenant.call_args_list,
            [call(self.context, self.tenant_id), ]
        )

        # User migration task created
        self.assertEqual(
            self.mock_user.call_args_list,
            [
                call(self.context,
                     self.user_id,
                     tenant_id=self.tenant_id)
            ]
        )

        # Tasks for each of roles
        self.assertEqual(
            self.mock_role.call_args_list,
            [call(self.context, r.id) for r in self.roles]
        )

        # Tasks for memberships of 0 and 2
        # [1] is skipped since it is started from "_"
        # [3] is skipped since there is such task in store already
        self.assertEqual(
            self.mock_member.call_args_list,
            [
                call(self.context,
                     self.user_id,
                     r.id,
                     self.tenant_id)
                for r in [self.roles[0], self.roles[2]]
            ]
        )
예제 #3
0
    def test_migrate_server_return(self):
        self.src_cloud.keystone.users.list_roles.return_value = [self.roles[0]]

        flow = identity.migrate_server_identity(
            self.context,
            self.server_info
        )

        self.assertEqual(self.context.store, {
            "role-role1_id-retrieve": "role1_id",
            "tenant-dummy_tenant_id-retrieve": "dummy_tenant_id",
            "user-dummy_user_id-retrieve": "dummy_user_id",
            "user-role-dummy_user_id-role1_id-dummy_tenant_id-ensure":
                "user-role-dummy_user_id-role1_id-dummy_tenant_id-ensure"
        })
        self.assertEqual(flow, self.mock_flow.return_value)
예제 #4
0
    def test_migrate_server_identity_tenant_and_user_exist(self):
        self.patchFlows()
        self.context.store = {
            "tenant-%s-retrieve" % self.tenant_id: True,
            "user-%s-retrieve" % self.user_id: True,
        }

        flow = identity.migrate_server_identity(
            self.context,
            self.server_info
        )

        # Assert neither migrate_tenant nor migrate_user are called if
        # corresponding ones exist in store
        self.assertFalse(self.mock_tenant.called)
        self.assertFalse(self.mock_user.called)