Merge lp:~gundlach/nova/get-server-rename-working into lp:~hudson-openstack/nova/trunk

Proposed by Michael Gundlach
Status: Merged
Approved by: Michael Gundlach
Approved revision: 442
Merged at revision: 438
Proposed branch: lp:~gundlach/nova/get-server-rename-working
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 187 lines (+21/-29)
5 files modified
nova/api/openstack/__init__.py (+2/-0)
nova/api/openstack/servers.py (+13/-19)
nova/compute/manager.py (+4/-6)
nova/tests/api/openstack/test_servers.py (+2/-2)
nova/virt/xenapi.py (+0/-2)
To merge this branch: bzr merge lp:~gundlach/nova/get-server-rename-working
Reviewer Review Type Date Requested Status
Sandy Walsh (community) Approve
Eric Day (community) Approve
Nova Core security contacts Pending
Review via email: mp+42537@code.launchpad.net

Description of the change

Fix bugs that prevented OpenStack API from supporting server rename.

To post a comment you must log in.
Revision history for this message
Eric Day (eday) wrote :

For line 91, can you have it use the self.compute_api.update_instance method instead? I'm trying to get all DB access out of the API servers. :)

review: Needs Fixing
Revision history for this message
Michael Gundlach (gundlach) wrote :

Eric: done :)

Revision history for this message
Eric Day (eday) wrote :

Thanks, looks good!

review: Approve
Revision history for this message
Sandy Walsh (sandy-walsh) wrote :

Looks good to me. Learned lots in the review too!

review: Approve
Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

The attempt to merge lp:~gundlach/nova/get-server-rename-working into lp:nova failed. Below is the output from the failed tests.

nova/tests/api/openstack/test_servers.py:51:26: E225 missing whitespace around operator
    return Instance(id=id+123456, state=0, image_id=10, user_id=user_id,
                         ^
    - Always surround these binary operators with a single space on
      either side: assignment (=), augmented assignment (+=, -= etc.),
      comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
      Booleans (and, or, not).

    - Use spaces around arithmetic operators.

    Okay: i = i + 1
    Okay: submitted += 1
    Okay: x = x * 2 - 1
    Okay: hypot2 = x * x + y * y
    Okay: c = (a + b) * (a - b)
    Okay: foo(bar, key='word', *args, **kwargs)
    Okay: baz(**kwargs)
    Okay: negative = -1
    Okay: spam(-1)
    Okay: alpha[:-i]
    Okay: if not -5 < x < +5:\n pass
    Okay: lambda *args, **kw: (args, kw)

    E225: i=i+1
    E225: submitted +=1
    E225: x = x*2 - 1
    E225: hypot2 = x*x + y*y
    E225: c = (a+b) * (a-b)
    E225: c = alpha -4
    E225: z = x **y

Revision history for this message
OpenStack Infra (hudson-openstack) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/__init__.py'
2--- nova/api/openstack/__init__.py 2010-10-25 16:22:29 +0000
3+++ nova/api/openstack/__init__.py 2010-12-02 21:36:43 +0000
4@@ -25,6 +25,7 @@
5
6 import logging
7 import routes
8+import traceback
9 import webob.dec
10 import webob.exc
11 import webob
12@@ -61,6 +62,7 @@
13 return req.get_response(self.application)
14 except Exception as ex:
15 logging.warn("Caught error: %s" % str(ex))
16+ logging.debug(traceback.format_exc())
17 exc = webob.exc.HTTPInternalServerError(explanation=str(ex))
18 return faults.Fault(exc)
19
20
21=== modified file 'nova/api/openstack/servers.py'
22--- nova/api/openstack/servers.py 2010-12-02 16:47:25 +0000
23+++ nova/api/openstack/servers.py 2010-12-02 21:36:43 +0000
24@@ -15,8 +15,6 @@
25 # License for the specific language governing permissions and limitations
26 # under the License.
27
28-import time
29-
30 import webob
31 from webob import exc
32
33@@ -36,16 +34,6 @@
34 FLAGS = flags.FLAGS
35
36
37-def _filter_params(inst_dict):
38- """ Extracts all updatable parameters for a server update request """
39- keys = dict(name='name', admin_pass='adminPass')
40- new_attrs = {}
41- for k, v in keys.items():
42- if v in inst_dict:
43- new_attrs[k] = inst_dict[v]
44- return new_attrs
45-
46-
47 def _entity_list(entities):
48 """ Coerces a list of servers into proper dictionary format """
49 return dict(servers=entities)
50@@ -64,7 +52,7 @@
51 inst_dict = {}
52
53 mapped_keys = dict(status='state', imageId='image_id',
54- flavorId='instance_type', name='display_name', id='id')
55+ flavorId='instance_type', name='display_name', id='internal_id')
56
57 for k, v in mapped_keys.iteritems():
58 inst_dict[k] = inst[v]
59@@ -79,7 +67,7 @@
60
61 def _entity_inst(inst):
62 """ Filters all model attributes save for id and name """
63- return dict(server=dict(id=inst['id'], name=inst['display_name']))
64+ return dict(server=dict(id=inst['internal_id'], name=inst['display_name']))
65
66
67 class Controller(wsgi.Controller):
68@@ -89,7 +77,7 @@
69 'application/xml': {
70 "attributes": {
71 "server": ["id", "imageId", "name", "flavorId", "hostId",
72- "status", "progress", "progress"]}}}
73+ "status", "progress"]}}}
74
75 def __init__(self, db_driver=None):
76 if not db_driver:
77@@ -173,10 +161,14 @@
78 if not instance or instance.user_id != user_id:
79 return faults.Fault(exc.HTTPNotFound())
80
81- self.db_driver.instance_update(ctxt,
82- int(id),
83- _filter_params(inst_dict['server']))
84- return faults.Fault(exc.HTTPNoContent())
85+ update_dict = {}
86+ if 'adminPass' in inst_dict['server']:
87+ update_dict['admin_pass'] = inst_dict['server']['adminPass']
88+ if 'name' in inst_dict['server']:
89+ update_dict['display_name'] = inst_dict['server']['name']
90+
91+ self.compute_api.update_instance(ctxt, instance['id'], update_dict)
92+ return exc.HTTPNoContent()
93
94 def action(self, req, id):
95 """ multi-purpose method used to reboot, rebuild, and
96@@ -191,6 +183,8 @@
97 inst_ref = self.db.instance_get_by_internal_id(ctxt, int(id))
98 if not inst_ref or (inst_ref and not inst_ref.user_id == user_id):
99 return faults.Fault(exc.HTTPUnprocessableEntity())
100+ #TODO(gundlach): pass reboot_type, support soft reboot in
101+ #virt driver
102 cloud.reboot(id)
103
104 def _get_network_topic(self, context):
105
106=== modified file 'nova/compute/manager.py'
107--- nova/compute/manager.py 2010-12-02 17:34:52 +0000
108+++ nova/compute/manager.py 2010-12-02 21:36:43 +0000
109@@ -22,8 +22,8 @@
110 The :py:class:`ComputeManager` class is a :py:class:`nova.manager.Manager` that
111 handles RPC calls relating to creating instances. It is responsible for
112 building a disk image, launching it via the underlying virtualization driver,
113-responding to calls to check it state, attaching persistent as well as
114-termination.
115+responding to calls to check its state, attaching persistent storage, and
116+terminating it.
117
118 **Related Flags**
119
120@@ -39,7 +39,6 @@
121
122 from twisted.internet import defer
123
124-from nova import db
125 from nova import exception
126 from nova import flags
127 from nova import manager
128@@ -50,10 +49,11 @@
129 flags.DEFINE_string('instances_path', '$state_path/instances',
130 'where instances are stored on disk')
131 flags.DEFINE_string('compute_driver', 'nova.virt.connection.get_connection',
132- 'Driver to use for volume creation')
133+ 'Driver to use for controlling virtualization')
134
135
136 class ComputeManager(manager.Manager):
137+
138 """Manages the running instances from creation to destruction."""
139
140 def __init__(self, compute_driver=None, *args, **kwargs):
141@@ -93,7 +93,6 @@
142 if instance_ref['name'] in self.driver.list_instances():
143 raise exception.Error("Instance has already been created")
144 logging.debug("instance %s: starting...", instance_id)
145- project_id = instance_ref['project_id']
146 self.network_manager.setup_compute_network(context, instance_id)
147 self.db.instance_update(context,
148 instance_id,
149@@ -135,7 +134,6 @@
150 self.db.instance_destroy(context, instance_id)
151 raise exception.Error('trying to destroy already destroyed'
152 ' instance: %s' % instance_id)
153-
154 yield self.driver.destroy(instance_ref)
155
156 # TODO(ja): should we keep it in a terminated state for a bit?
157
158=== modified file 'nova/tests/api/openstack/test_servers.py'
159--- nova/tests/api/openstack/test_servers.py 2010-12-02 16:47:25 +0000
160+++ nova/tests/api/openstack/test_servers.py 2010-12-02 21:36:43 +0000
161@@ -48,8 +48,8 @@
162
163
164 def stub_instance(id, user_id=1):
165- return Instance(id=id, state=0, image_id=10, display_name='server%s' % id,
166- user_id=user_id)
167+ return Instance(id=id + 123456, state=0, image_id=10, user_id=user_id,
168+ display_name='server%s' % id, internal_id=id)
169
170
171 class ServersTest(unittest.TestCase):
172
173=== modified file 'nova/virt/xenapi.py'
174--- nova/virt/xenapi.py 2010-11-22 13:11:00 +0000
175+++ nova/virt/xenapi.py 2010-12-02 21:36:43 +0000
176@@ -52,11 +52,9 @@
177
178 from twisted.internet import defer
179 from twisted.internet import reactor
180-from twisted.internet import task
181
182 from nova import db
183 from nova import flags
184-from nova import process
185 from nova import utils
186 from nova.auth.manager import AuthManager
187 from nova.compute import instance_types