def refresh(self, request, id): """@description-title Refresh a pod @description Performs pod discovery and updates all discovered information and discovered machines. @param (int) "{id}" [required=false] The pod's ID. @success (json) "success-json" A pod JSON object. @success-example "success-json" [exkey=refresh-pod] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" No pod with that ID can be found. @error-example "not-found" Not Found @error (http-status-code) "403" 403 @error (content) "no-perms" The user does not have the permissions to delete the pod. @error-example (content) "no-perms" This method is reserved for admin users. """ pod = Pod.objects.get_pod_or_404(id, request.user, PodPermission.edit) form = PodForm(data=request.data, instance=pod, request=request) pod = form.discover_and_sync_pod() return pod
def test_discover_and_sync_existing_pod(self): discovered_pod, discovered_racks, failed_racks = ( self.fake_pod_discovery()) pod_info = self.make_pod_info() orig_pod = factory.make_Pod(pod_type=pod_info['type']) request = MagicMock() request.user = factory.make_User() form = PodForm(data=pod_info, request=request, instance=orig_pod) pod = form.discover_and_sync_pod() self.assertThat( pod, MatchesStructure( id=Equals(orig_pod.id), bmc_type=Equals(BMC_TYPE.POD), architectures=Equals(['amd64/generic']), name=Equals(orig_pod.name), cores=Equals(discovered_pod.cores), memory=Equals(discovered_pod.memory), cpu_speed=Equals(discovered_pod.cpu_speed), power_type=Equals(pod_info['type']), power_parameters=Equals({}), ip_address=Is(None), )) routable_racks = [ relation.rack_controller for relation in pod.routable_rack_relationships.all() if relation.routable ] not_routable_racks = [ relation.rack_controller for relation in pod.routable_rack_relationships.all() if not relation.routable ] self.assertItemsEqual(routable_racks, discovered_racks) self.assertItemsEqual(not_routable_racks, failed_racks)
def refresh(self, request, id): """Refresh a specific Pod. Performs pod discovery and updates all discovered information and discovered machines. Returns 404 if the pod is not found. Returns 403 if the user does not have permission to refresh the pod. """ pod = get_object_or_404(Pod, id=id) form = PodForm(data=request.data, instance=pod, request=request) pod = form.discover_and_sync_pod() return pod