Browse Source

Support install suppack multi times

When add a new VM to current MOS environment, our plugins script
compute_post_deployment.py will be triggered and it will try to
install the supplemental packages and got the exception like:
"This update has already been applied", this patch is to add the
acceptable return code 1 when execute xe-install-supplemental-pack

Change-Id: Ie4e4328ed85938a6f98b272858ce3a39f9d564d4
Huan Xie 2 years ago
parent
commit
3009f637e2

+ 33
- 2
plugin_source/deployment_scripts/compute_post_deployment.py View File

@@ -129,6 +129,15 @@ def route_to_compute(endpoints, himn_xs, himn_local, username):
129 129
                '> /etc/udev/rules.d/90-reroute.rules'))
130 130
 
131 131
 
132
+def parse_uuid(output):
133
+    uuid = None
134
+    index = output.strip().find('uuid:')
135
+    if index >= 0:
136
+        start = index + len('uuid:')
137
+        uuid = output[start:].strip()
138
+    return uuid
139
+
140
+
132 141
 def install_suppack(himn, username, package, xcp_version):
133 142
     """Install xapi driver supplemental pack. """
134 143
     tmp = utils.ssh(himn, username, 'mktemp', '-d')
@@ -136,8 +145,30 @@ def install_suppack(himn, username, package, xcp_version):
136 145
     if not os.path.exists(real_pack):
137 146
         utils.reportError('Package folder %s not exist' % real_pack)
138 147
     utils.scp(himn, username, tmp, real_pack)
139
-    utils.ssh(himn, username, 'xe-install-supplemental-pack',
140
-              tmp + '/' + package, prompt='Y\n')
148
+    if LooseVersion(xcp_version) < LooseVersion('2.2.0'):
149
+        utils.ssh(himn, username, 'xe-install-supplemental-pack',
150
+                  tmp + '/' + package, prompt='Y\n')
151
+    else:
152
+        errcode, uuid, errmsg = \
153
+            utils.ssh_detailed(himn, username, 'xe', 'update-upload',
154
+                               'file-name=' + tmp + '/' + package,
155
+                               allowed_return_codes=[0, 1])
156
+        if errcode == 0:
157
+            utils.ssh(himn, username, 'xe', 'update-apply',
158
+                      'uuid=' + uuid.strip())
159
+        else:
160
+            LOG.debug("Install supplemental pack failed, err: %s", errmsg)
161
+            if "The uploaded update already exists" in errmsg:
162
+                uuid = parse_uuid(errmsg)
163
+                if uuid is None:
164
+                    raise utils.ExecutionError(errmsg)
165
+                # Check current update is applied already
166
+                out = utils.ssh(himn, username, 'xe', 'update-list',
167
+                                'uuid=' + uuid, '--minimal')
168
+                # Apply this update if cannot find it with uuid
169
+                if not out:
170
+                    utils.ssh(himn, username, 'xe', 'update-apply',
171
+                              'uuid=' + uuid)
141 172
     utils.ssh(himn, username, 'rm', tmp, '-rf')
142 173
 
143 174
 

+ 9
- 2
plugin_source/deployment_scripts/utils.py View File

@@ -103,8 +103,15 @@ def ssh(host, username, *cmd, **kwargs):
103 103
 
104 104
     return execute('ssh', '-i', XS_RSA,
105 105
                    '-o', 'StrictHostKeyChecking=no',
106
-                   '%s@%s' % (username, host), *cmd,
107
-                   prompt=kwargs.get('prompt'))
106
+                   '%s@%s' % (username, host), *cmd, **kwargs)
107
+
108
+
109
+def ssh_detailed(host, username, *cmd, **kwargs):
110
+    cmd = map(str, cmd)
111
+
112
+    return detailed_execute('ssh', '-i', XS_RSA,
113
+                            '-o', 'StrictHostKeyChecking=no',
114
+                            '%s@%s' % (username, host), *cmd, **kwargs)
108 115
 
109 116
 
110 117
 def scp(host, username, target_path, filename):

Loading…
Cancel
Save