def test_stack(): api_mock = MagicMock(spec=NamespacedAPIObject, name="APIMock") scalable_mock = {"spec": {"replicas": 3}} api_mock.obj = MagicMock(name="APIObjMock") d = Stack(api_mock, scalable_mock) r = d.replicas assert r == 3 d.replicas = 10 assert scalable_mock["spec"]["replicas"] == 10
def test_stack(): api_mock = MagicMock(spec=NamespacedAPIObject, name="APIMock") scalable_mock = {'spec': {'replicas': 3}} api_mock.obj = MagicMock(name="APIObjMock") d = Stack(api_mock, scalable_mock) r = d.replicas assert r == 3 d.replicas = 10 assert scalable_mock['spec']['replicas'] == 10
def test_downscale_stack_with_autoscaling(): stack = Stack( None, { "metadata": { "name": "my-stack", "namespace": "my-ns", "creationTimestamp": "2018-10-23T21:55:00Z", }, "spec": { "horizontalPodAutoscaler": { "maxReplicas": 4 } }, }, ) now = datetime.strptime("2018-10-23T21:56:00Z", "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc) assert stack.replicas == 4 autoscale_resource( stack, upscale_period="never", downscale_period="never", default_uptime="never", default_downtime="always", forced_uptime=False, dry_run=True, now=now, ) assert stack.replicas == 0
def test_upscale_stack_with_autoscaling(): stack = Stack( None, { "metadata": { "name": "my-stack", "namespace": "my-ns", "creationTimestamp": "2018-10-23T21:55:00Z", "annotations": { ORIGINAL_REPLICAS_ANNOTATION: 4 }, }, "spec": { "autoscaler": { "maxReplicas": 4 }, "replicas": 0 }, }, ) now = datetime.strptime("2018-10-23T21:56:00Z", "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=timezone.utc) assert stack.replicas == 0 autoscale_resource( stack, upscale_period="never", downscale_period="never", default_uptime="always", default_downtime="never", forced_uptime=False, dry_run=True, enable_events=False, now=now, ) assert stack.obj["spec"]["replicas"] is None assert stack.replicas == 4 assert stack.annotations[ORIGINAL_REPLICAS_ANNOTATION] is None