def handle(self, request, data): cgroup_id = self.initial['cgroup_id'] name = self.initial['name'] search_opts = {'consistencygroup_id': cgroup_id} try: # get list of assigned volumes assigned_vols = [] volumes = cinder.volume_list(request, search_opts=search_opts) for volume in volumes: assigned_vols.append(volume.id) assigned_vols_str = ",".join(assigned_vols) cinder.volume_cgroup_update(request, cgroup_id, remove_vols=assigned_vols_str) message = _('Removing volumes from volume consistency ' 'group "%s"') % name messages.info(request, message) return True except Exception: redirect = reverse("horizon:admin:volumes:index") exceptions.handle(request, _('Errors occurred in removing volumes ' 'from consistency group.'), redirect=redirect)
def handle(self, request, data): cgroup_id = self.initial['cgroup_id'] name = self.initial['name'] search_opts = {'consistencygroup_id': cgroup_id} try: # get list of assigned volumes assigned_vols = [] volumes = cinder.volume_list(request, search_opts=search_opts) for volume in volumes: assigned_vols.append(volume.id) assigned_vols_str = ",".join(assigned_vols) cinder.volume_cgroup_update(request, cgroup_id, remove_vols=assigned_vols_str) message = _('Removing volumes from volume consistency ' 'group "%s"') % name messages.info(request, message) return True except Exception: redirect = reverse("horizon:project:volumes:index") exceptions.handle(request, _('Errors occurred in removing volumes ' 'from consistency group.'), redirect=redirect)
def test_update_cgroup_remove_vol(self): cgroup = self.cinder_consistencygroups.first() volume = self.cinder_volumes.first() formData = { 'volume_types': '1', 'name': 'test CG', 'description': 'test desc' } cinder.volume_cgroup_get(IsA( http.HttpRequest), cgroup.id).\ AndReturn(cgroup) cinder.volume_cgroup_update( IsA(http.HttpRequest), formData['name'], formData['description'], remove_vols=volume)\ .AndReturn(cgroup) self.mox.ReplayAll() url = reverse('horizon:compute_user:volume2:cgroups:update', args=[cgroup.id]) res = self.client.post(url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
def handle(self, request, data): cgroup_id = self.initial['cgroup_id'] try: cinder.volume_cgroup_update(request, cgroup_id, data['name'], data['description']) message = _('Updating volume consistency ' 'group "%s"') % data['name'] messages.info(request, message) return True except Exception: redirect = reverse("horizon:virtual:volumes:index") exceptions.handle(request, _('Unable to update volume consistency group.'), redirect=redirect)
def handle(self, request, context): cgroup_id = context['cgroup_id'] add_vols = [] remove_vols = [] try: selected_volumes = context['volumes'] volumes = cinder.volume_list(request) # scan all volumes and make correct consistency group is set for volume in volumes: selected = False for selection in selected_volumes: if selection == volume.id: selected = True break if selected: # ensure this volume is in this consistency group if hasattr(volume, 'consistencygroup_id'): if volume.consistencygroup_id != cgroup_id: add_vols.append(volume.id) else: add_vols.append(volume.id) else: # ensure this volume is not in our consistency group if hasattr(volume, 'consistencygroup_id'): if volume.consistencygroup_id == cgroup_id: # remove from this CG remove_vols.append(volume.id) add_vols_str = ",".join(add_vols) remove_vols_str = ",".join(remove_vols) if not add_vols_str and not remove_vols_str: # nothing to change return True cinder.volume_cgroup_update(request, cgroup_id, name=context['name'], add_vols=add_vols_str, remove_vols=remove_vols_str) except Exception: # error message supplied by form return False return True
def test_update_cgroup_name_and_description(self): cgroup = self.cinder_consistencygroups.first() formData = {'volume_types': '1', 'name': 'test CG-new', 'description': 'test desc-new'} cinder.volume_cgroup_get(IsA( http.HttpRequest), cgroup.id).\ AndReturn(cgroup) cinder.volume_cgroup_update( IsA(http.HttpRequest), formData['name'], formData['description'])\ .AndReturn(cgroup) self.mox.ReplayAll() url = reverse('horizon:project:volumes:cgroups:update', args=[cgroup.id]) res = self.client.post(url, formData) self.assertNoFormErrors(res)
def test_update_cgroup_with_exception(self): cgroup = self.cinder_consistencygroups.first() formData = {'volume_types': '1', 'name': 'test CG-new', 'description': 'test desc-new'} cinder.volume_cgroup_get(IsA( http.HttpRequest), cgroup.id).\ AndReturn(cgroup) cinder.volume_cgroup_update( IsA(http.HttpRequest), formData['name'], formData['description'])\ .AndRaise(self.exceptions.cinder) self.mox.ReplayAll() url = reverse('horizon:project:volumes:cgroups:update', args=[cgroup.id]) res = self.client.post(url, formData) self.assertRedirectsNoFollow(res, VOLUME_INDEX_URL)
def test_update_cgroup_remove_vol(self): cgroup = self.cinder_consistencygroups.first() volume = self.cinder_volumes.first() formData = {'volume_types': '1', 'name': 'test CG', 'description': 'test desc'} cinder.volume_cgroup_get(IsA( http.HttpRequest), cgroup.id).\ AndReturn(cgroup) cinder.volume_cgroup_update( IsA(http.HttpRequest), formData['name'], formData['description'], remove_vols=volume)\ .AndReturn(cgroup) self.mox.ReplayAll() url = reverse('horizon:project:cgroups:update', args=[cgroup.id]) res = self.client.post(url, formData) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
def handle(self, request, context): cgroup_id = context['cgroup_id'] add_vols = [] remove_vols = [] try: selected_volumes = context['volumes'] volumes = cinder.volume_list(request) # scan all volumes and make correct consistency group is set for volume in volumes: selected = False for selection in selected_volumes: if " [" in selection: # handle duplicate volume names sel = selection.split(" [") sel_vol_name = sel[0] sel_vol_id = sel[1].split("]")[0] else: sel_vol_name = selection sel_vol_id = None if volume.name == sel_vol_name: if sel_vol_id: if sel_vol_id == volume.id: selected = True else: selected = True if selected: break if selected: # ensure this volume is in this consistency group if hasattr(volume, 'consistencygroup_id'): if volume.consistencygroup_id != cgroup_id: add_vols.append(volume.id) else: add_vols.append(volume.id) else: # ensure this volume is not in our consistency group if hasattr(volume, 'consistencygroup_id'): if volume.consistencygroup_id == cgroup_id: remove_vols.append(volume.id) add_vols_str = ",".join(add_vols) remove_vols_str = ",".join(remove_vols) cinder.volume_cgroup_update(request, cgroup_id, name=context['name'], add_vols=add_vols_str, remove_vols=remove_vols_str) # before returning, ensure all new volumes are correctly assigned self._verify_changes(request, cgroup_id, add_vols, remove_vols) message = _('Updating volume consistency ' 'group "%s"') % context['name'] messages.info(request, message) except Exception: exceptions.handle(request, _('Unable to edit consistency group.')) return False return True