This new parameter, "restartPolicy", will allow define the restart policy per pod.
Example of yaml definition in Kubernetes:
apiVersion: v1
kind: Pod
metadata:
name: frontend
spec:
containers:
- name: db
...
restartPolicy: Always # Possible values: "Always", "OnFailure" and "Never"
Example of definition in a Yardstick context:
context:
type: Kubernetes
servers:
host:
containers:
- name: ...
restartPolicy: Always # Default value: "Always"
Restart policy [1].
[1] https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/#restart-policy
JIRA: YARDSTICK-1175
Change-Id: Id4317b909f98422e89d6d4553e8cfb0e1f593355
Signed-off-by: John O Loughlin <john.oloughlin@intel.com>
message = 'Kubernetes kind "Network" is not defined'
+class KubernetesWrongRestartPolicy(YardstickException):
+ message = 'Restart policy "%(rpolicy)s" is not valid'
+
+
class ScenarioCreateNetworkError(YardstickException):
message = 'Create Neutron Network Scenario failed'
class ReplicationControllerObject(object):
SSHKEY_DEFAULT = 'yardstick_key'
+ RESTART_POLICY = ('Always', 'OnFailure', 'Never')
def __init__(self, name, **kwargs):
super(ReplicationControllerObject, self).__init__()
self._volumes = parameters.pop('volumes', [])
self._security_context = parameters.pop('securityContext', None)
self._networks = parameters.pop('networks', [])
+ self._restart_policy = parameters.pop('restartPolicy', 'Always')
+ if self._restart_policy not in self.RESTART_POLICY:
+ raise exceptions.KubernetesWrongRestartPolicy(
+ rpolicy=self._restart_policy)
containers = parameters.pop('containers', None)
if containers:
"spec": {
"containers": [],
"volumes": [],
- "nodeSelector": {}
+ "nodeSelector": {},
+ "restartPolicy": self._restart_policy
}
}
}
],
"nodeSelector": {
"kubernetes.io/hostname": "node-01"
- }
+ },
+ "restartPolicy": "Always"
}
}
}
service ssh restart;while true ; do sleep 10000; done'],
'ssh_key': 'k8s-86096c30-key',
'nodeSelector': {'kubernetes.io/hostname': 'node-01'},
- 'volumes': []
+ 'volumes': [],
+ 'restartPolicy': 'Always'
}
name = 'host-k8s-86096c30'
output_r = kubernetes.ReplicationControllerObject(
name, **input_s).get_template()
self.assertEqual(output_r, output_t)
+ def test_get_template_invalid_restart_policy(self):
+ input_s = {'restartPolicy': 'invalid_option'}
+ name = 'host-k8s-86096c30'
+ with self.assertRaises(exceptions.KubernetesWrongRestartPolicy):
+ kubernetes.ReplicationControllerObject(
+ name, **input_s).get_template()
+
class GetRcPodsTestCase(base.BaseUnitTestCase):
'limits': {'key2': 'val2'}}}
self.assertEqual(expected, container_obj.get_container_item())
+
class CustomResourceDefinitionObjectTestCase(base.BaseUnitTestCase):
def test__init(self):