1 # Copyright 2020 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from unittest
import TestCase
17 from n2vc
.utils
import (
24 from juju
.machine
import Machine
25 from juju
.application
import Application
26 from juju
.action
import Action
27 from juju
.unit
import Unit
30 class UtilsTest(TestCase
):
32 example
= Dict({"key": "value"})
33 self
.assertEqual(example
["key"], example
.key
)
35 def test_entity_type(self
):
36 self
.assertFalse(EntityType
.has_value("machine2"))
37 values
= [Machine
, Application
, Action
, Unit
]
39 self
.assertTrue(EntityType
.has_value(value
))
41 self
.assertEqual(EntityType
.MACHINE
, EntityType
.get_entity(Machine
))
42 self
.assertEqual(EntityType
.APPLICATION
, EntityType
.get_entity(Application
))
43 self
.assertEqual(EntityType
.UNIT
, EntityType
.get_entity(Unit
))
44 self
.assertEqual(EntityType
.ACTION
, EntityType
.get_entity(Action
))
46 def test_juju_status_to_osm(self
):
49 "entity_type": "machine",
51 {"juju": "pending", "osm": N2VCDeploymentStatus
.PENDING
},
52 {"juju": "started", "osm": N2VCDeploymentStatus
.COMPLETED
},
56 "entity_type": "application",
58 {"juju": "waiting", "osm": N2VCDeploymentStatus
.RUNNING
},
59 {"juju": "maintenance", "osm": N2VCDeploymentStatus
.RUNNING
},
60 {"juju": "blocked", "osm": N2VCDeploymentStatus
.RUNNING
},
61 {"juju": "error", "osm": N2VCDeploymentStatus
.FAILED
},
62 {"juju": "active", "osm": N2VCDeploymentStatus
.COMPLETED
},
66 "entity_type": "unit",
68 {"juju": "waiting", "osm": N2VCDeploymentStatus
.RUNNING
},
69 {"juju": "maintenance", "osm": N2VCDeploymentStatus
.RUNNING
},
70 {"juju": "blocked", "osm": N2VCDeploymentStatus
.RUNNING
},
71 {"juju": "error", "osm": N2VCDeploymentStatus
.FAILED
},
72 {"juju": "active", "osm": N2VCDeploymentStatus
.COMPLETED
},
76 "entity_type": "action",
78 {"juju": "running", "osm": N2VCDeploymentStatus
.RUNNING
},
79 {"juju": "completed", "osm": N2VCDeploymentStatus
.COMPLETED
},
85 entity_type
= test
["entity_type"]
86 self
.assertTrue(entity_type
in JujuStatusToOSM
)
88 for status
in test
["status"]:
89 juju_status
= status
["juju"]
90 osm_status
= status
["osm"]
91 self
.assertTrue(juju_status
in JujuStatusToOSM
[entity_type
])
92 self
.assertEqual(osm_status
, JujuStatusToOSM
[entity_type
][juju_status
])
95 class GetEEComponentTest(TestCase
):
97 model
, application
, machine
= get_ee_id_components("model.application.machine")
98 self
.assertEqual(model
, "model")
99 self
.assertEqual(application
, "application")
100 self
.assertEqual(machine
, "machine")
102 def test_invalid(self
):
103 with self
.assertRaises(Exception):
104 get_ee_id_components("model.application.machine.1")
105 with self
.assertRaises(Exception):
106 get_ee_id_components("model.application")