Ejemplo n.º 1
0
 def test_list_params_juju_2_4(self):
     change = AddApplicationChange(1, [],
                                   params=[
                                       "charm", "series", "application",
                                       "options", "constraints", {
                                           "db": "pool,1,1GB"
                                       }, "endpoint_bindings", "resources"
                                   ])
     self.assertEqual(
         {
             "change_id": 1,
             "requires": [],
             "charm": "charm",
             "series": "series",
             "application": "application",
             "options": "options",
             "constraints": "constraints",
             "storage": {
                 "db": {
                     "pool": "pool",
                     "count": 1,
                     "size": 1024
                 }
             },
             "endpoint_bindings": "endpoint_bindings",
             "resources": "resources",
             "devices": None,
             "num_units": None
         }, change.__dict__)
Ejemplo n.º 2
0
 def test_dict_params_missing_data(self):
     change = AddApplicationChange(1, [],
                                   params={
                                       "charm": "charm",
                                       "series": "series",
                                       "application": "application",
                                       "options": "options",
                                       "constraints": "constraints",
                                       "storage": "storage"
                                   })
     self.assertEqual(
         {
             "change_id": 1,
             "requires": [],
             "charm": "charm",
             "series": "series",
             "application": "application",
             "options": "options",
             "constraints": "constraints",
             "storage": "storage",
             "endpoint_bindings": None,
             "resources": None,
             "devices": None,
             "num_units": None
         }, change.__dict__)
Ejemplo n.º 3
0
    async def test_run_with_charmstore_charm(self, event_loop):
        change = AddApplicationChange(1, [],
                                      params={
                                          "charm": "cs:charm",
                                          "series": "series",
                                          "application": "application",
                                          "options": "options",
                                          "constraints": "constraints",
                                          "storage": "storage",
                                          "endpoint-bindings":
                                          "endpoint_bindings",
                                          "resources": "resources",
                                          "devices": "devices",
                                          "num-units": "num_units",
                                          "channel": "channel"
                                      })

        model = mock.Mock()
        model._deploy = base.AsyncMock(return_value=None)
        model._add_store_resources = base.AsyncMock(return_value=["resource1"])
        model.applications = {}

        context = mock.Mock()
        context.resolve.return_value = "cs:charm1"
        context.origins = {"cs:charm1": {"channel/stable": {}}}
        context.trusted = False
        context.model = model

        result = await change.run(context)
        assert result == "application"

        model._add_store_resources.assert_called_once()
        model._add_store_resources.assert_called_with("application",
                                                      "cs:charm1",
                                                      overrides="resources")

        model._deploy.assert_called_once()
        model._deploy.assert_called_with(charm_url="cs:charm1",
                                         application="application",
                                         series="series",
                                         config="options",
                                         constraints="constraints",
                                         endpoint_bindings="endpoint_bindings",
                                         resources=["resource1"],
                                         storage="storage",
                                         devices="devices",
                                         num_units="num_units")

        # confirm that it's idempotent
        model.applications = {"application": None}
        result = await change.run(context)
        assert result == "application"
        model._add_store_resources.assert_called_once()
        model._deploy.assert_called_once()
Ejemplo n.º 4
0
 def test_list_params_juju_2_5(self):
     change = AddApplicationChange(1, [],
                                   params=[
                                       "charm", "series", "application",
                                       "options", "constraints", {
                                           "db": "pool,1,1GB"
                                       }, {
                                           "gpu": "1,gpu,attr1=a;attr2=b"
                                       }, "endpoint_bindings", "resources",
                                       "num_units"
                                   ])
     self.assertEqual(
         {
             "change_id": 1,
             "requires": [],
             "charm": "charm",
             "series": "series",
             "application": "application",
             "options": "options",
             "constraints": "constraints",
             "storage": {
                 "db": {
                     "pool": "pool",
                     "count": 1,
                     "size": 1024
                 }
             },
             "endpoint_bindings": "endpoint_bindings",
             "resources": "resources",
             "devices": {
                 "gpu": {
                     "type": "gpu",
                     "count": 1,
                     "attributes": {
                         "attr1": "a",
                         "attr2": "b"
                     }
                 }
             },
             "num_units": "num_units"
         }, change.__dict__)
Ejemplo n.º 5
0
    async def test_run_local(self, event_loop):
        change = AddApplicationChange(1, [],
                                      params={
                                          "charm": "local:charm",
                                          "series": "series",
                                          "application": "application",
                                          "options": "options",
                                          "constraints": "constraints",
                                          "storage": "storage",
                                          "endpoint-bindings":
                                          "endpoint_bindings",
                                          "devices": "devices",
                                          "num-units": "num_units"
                                      })

        model = mock.Mock()
        model._deploy = base.AsyncMock(return_value=None)
        model.applications = {}

        context = mock.Mock()
        context.resolve.return_value = "local:charm1"
        context.trusted = False
        context.model = model
        context.bundle = {"applications": {}}

        result = await change.run(context)
        assert result == "application"

        model._deploy.assert_called_once()
        model._deploy.assert_called_with(charm_url="local:charm1",
                                         application="application",
                                         series="series",
                                         config="options",
                                         constraints="constraints",
                                         endpoint_bindings="endpoint_bindings",
                                         resources={},
                                         storage="storage",
                                         devices="devices",
                                         num_units="num_units")
Ejemplo n.º 6
0
 def test_list_params_juju_2_5(self):
     change = AddApplicationChange(1, [],
                                   params=[
                                       "charm", "series", "application",
                                       "options", "constraints", "storage",
                                       "endpoint_bindings", "devices",
                                       "resources", "num_units"
                                   ])
     self.assertEqual(
         {
             "change_id": 1,
             "requires": [],
             "charm": "charm",
             "series": "series",
             "application": "application",
             "options": "options",
             "constraints": "constraints",
             "storage": "storage",
             "endpoint_bindings": "endpoint_bindings",
             "resources": "resources",
             "devices": "devices",
             "num_units": "num_units"
         }, change.__dict__)
Ejemplo n.º 7
0
 def test_method(self):
     self.assertEqual("deploy", AddApplicationChange.method())