def test_delete(self): """Test delete method.""" vop = VolumeOp(name="vop", resource_name="vop", size="1Gi") delete_vop = vop.delete() expected_name = str(vop.outputs['name']) self.assertEqual(delete_vop.command, [ 'kubectl', 'delete', 'PersistentVolumeClaim', expected_name, '--ignore-not-found', '--output', 'name' ]) self.assertEqual(delete_vop.outputs, {})
def my_pipeline(param1, param2): vol = VolumeOp(name="myvol_creation", resource_name=param1, size=param2, annotations={"test": "annotation"}) self.assertCountEqual([x.name for x in vol.inputs], ["param1", "param2"]) self.assertEqual(vol.k8s_resource.metadata.name, "{{workflow.name}}-%s" % str(param1)) expected_attribute_outputs = { "manifest": "{}", "name": "{.metadata.name}", "size": "{.status.capacity.storage}" } self.assertEqual(vol.attribute_outputs, expected_attribute_outputs) expected_outputs = { "manifest": PipelineParam(name="manifest", op_name=vol.name), "name": PipelineParam(name="name", op_name=vol.name), "size": PipelineParam(name="size", op_name=vol.name) } self.assertEqual(vol.outputs, expected_outputs) self.assertEqual(vol.output, PipelineParam(name="name", op_name=vol.name)) self.assertEqual(vol.dependent_names, []) expected_volume = PipelineVolume( name="myvol-creation", persistent_volume_claim=V1PersistentVolumeClaimVolumeSource( claim_name=PipelineParam(name="name", op_name=vol.name)))
def test_delete(self): """Test delete method.""" vop = VolumeOp(name="vop", resource_name="vop", size="1Gi") delete_vop = vop.delete() self.assertEqual(delete_vop.resource.action, "delete") self.assertEqual(delete_vop.attribute_outputs, {}) self.assertEqual(delete_vop.outputs, {}) self.assertEqual(delete_vop.output, None) expected_name = PipelineParam(name="name", op_name=vop.name) expected_resource = { "apiVersion": "v1", "kind": "PersistentVolumeClaim", "metadata": { "name": expected_name } } self.assertEqual(delete_vop.k8s_resource, expected_resource) with self.assertRaises(ValueError): delete_vop.delete()
def my_pipeline(): vol = VolumeOp(name="myvol_creation", resource_name="myvol", size="1Gi") op1 = ContainerOp(name="op1", image="image", pvolumes={"/mnt": vol.volume}) op2 = ContainerOp(name="op2", image="image", pvolumes={"/data": op1.pvolume}) self.assertEqual(vol.volume.dependent_names, []) self.assertEqual(op1.pvolume.dependent_names, [op1.name]) self.assertEqual(op2.dependent_names, [op1.name])
def test_basic(self): """Test basic usage.""" with Pipeline("somename") as p: vol = VolumeOp(name="myvol_creation", resource_name="myvol", size="1Gi") op1 = ContainerOp(name="op1", image="image", pvolumes={"/mnt": vol.volume}) op2 = ContainerOp(name="op2", image="image", pvolumes={"/data": op1.pvolume}) self.assertEqual(vol.volume.dependent_names, []) self.assertEqual(op1.pvolume.dependent_names, [op1.name]) self.assertEqual(op2.dependent_names, [op1.name])
def my_pipeline(param1, param2): vol = VolumeOp( name="myvol_creation", resource_name="myvol", size="1Gi", ) snap1 = VolumeSnapshotOp( name="mysnap_creation", resource_name=param1, volume=vol.volume, ) snap2 = VolumeSnapshotOp(name="mysnap_creation", resource_name="mysnap", pvc=param2, attribute_outputs={"size": "test"}) snap3 = VolumeSnapshotOp( name="mysnap_creation2", resource_name="mysnap2", pvc=param2, api_version="snapshot.storage.k8s.io/v1beta1", attribute_outputs={"size": "test"}) self.assertEqual(sorted([x.name for x in snap1.inputs]), ["name", "param1"]) self.assertEqual(sorted([x.name for x in snap2.inputs]), ["param2"]) expected_attribute_outputs_1 = { "manifest": "{}", "name": "{.metadata.name}", "size": "{.status.restoreSize}" } self.assertEqual(snap1.attribute_outputs, expected_attribute_outputs_1) expected_attribute_outputs_2 = { "manifest": "{}", "name": "{.metadata.name}", "size": "test" } self.assertEqual(snap2.attribute_outputs, expected_attribute_outputs_2) expected_outputs_1 = { "manifest": PipelineParam(name="manifest", op_name=snap1.name), "name": PipelineParam(name="name", op_name=snap1.name), "size": PipelineParam(name="name", op_name=snap1.name), } self.assertEqual(snap1.outputs, expected_outputs_1) expected_outputs_2 = { "manifest": PipelineParam(name="manifest", op_name=snap2.name), "name": PipelineParam(name="name", op_name=snap2.name), "size": PipelineParam(name="name", op_name=snap2.name), } self.assertEqual(snap2.outputs, expected_outputs_2) self.assertEqual(snap1.output, PipelineParam(name="name", op_name=snap1.name)) self.assertEqual(snap2.output, PipelineParam(name="size", op_name=snap2.name)) self.assertEqual(snap1.dependent_names, []) self.assertEqual(snap2.dependent_names, []) expected_snapshot_1 = k8s_client.V1TypedLocalObjectReference( api_group="snapshot.storage.k8s.io", kind="VolumeSnapshot", name=PipelineParam(name="name", op_name=vol.name)) self.assertEqual(snap1.snapshot, expected_snapshot_1) expected_snapshot_2 = k8s_client.V1TypedLocalObjectReference( api_group="snapshot.storage.k8s.io", kind="VolumeSnapshot", name=PipelineParam(name="param1")) assert (snap2.k8s_resource['apiVersion'] == "snapshot.storage.k8s.io/v1alpha1") self.assertEqual(snap2.snapshot, expected_snapshot_2) expected_snapshot_3 = k8s_client.V1TypedLocalObjectReference( api_group="snapshot.storage.k8s.io", kind="VolumeSnapshot", name=PipelineParam(name="param1")) self.assertEqual(snap3.snapshot, expected_snapshot_3) assert (snap3.k8s_resource['apiVersion'] == "snapshot.storage.k8s.io/v1beta1")
def test_basic(self): """Test basic usage.""" with Pipeline("somename") as p: param1 = PipelineParam("param1") param2 = PipelineParam("param2") vol = VolumeOp( name="myvol_creation", resource_name="myvol", size="1Gi", ) snap1 = VolumeSnapshotOp( name="mysnap_creation", resource_name=param1, volume=vol.volume, ) snap2 = VolumeSnapshotOp( name="mysnap_creation", resource_name="mysnap", pvc=param2, attribute_outputs={"size": "test"} ) self.assertEqual( sorted([x.name for x in snap1.inputs]), ["name", "param1"] ) self.assertEqual( sorted([x.name for x in snap2.inputs]), ["param2"] ) expected_attribute_outputs_1 = { "manifest": "{}", "name": "{.metadata.name}", "size": "{.status.restoreSize}" } self.assertEqual(snap1.attribute_outputs, expected_attribute_outputs_1) expected_attribute_outputs_2 = { "manifest": "{}", "name": "{.metadata.name}", "size": "test" } self.assertEqual(snap2.attribute_outputs, expected_attribute_outputs_2) expected_outputs_1 = { "manifest": PipelineParam(name="manifest", op_name=snap1.name), "name": PipelineParam(name="name", op_name=snap1.name), "size": PipelineParam(name="name", op_name=snap1.name), } self.assertEqual(snap1.outputs, expected_outputs_1) expected_outputs_2 = { "manifest": PipelineParam(name="manifest", op_name=snap2.name), "name": PipelineParam(name="name", op_name=snap2.name), "size": PipelineParam(name="name", op_name=snap2.name), } self.assertEqual(snap2.outputs, expected_outputs_2) self.assertEqual( snap1.output, PipelineParam(name="name", op_name=snap1.name) ) self.assertEqual( snap2.output, PipelineParam(name="size", op_name=snap2.name) ) self.assertEqual(snap1.dependent_names, []) self.assertEqual(snap2.dependent_names, []) expected_snapshot_1 = k8s_client.V1TypedLocalObjectReference( api_group="snapshot.storage.k8s.io", kind="VolumeSnapshot", name=PipelineParam(name="name", op_name=vol.name) ) self.assertEqual(snap1.snapshot, expected_snapshot_1) expected_snapshot_2 = k8s_client.V1TypedLocalObjectReference( api_group="snapshot.storage.k8s.io", kind="VolumeSnapshot", name=PipelineParam(name="param1") ) self.assertEqual(snap2.snapshot, expected_snapshot_2)