Functionality is supported both for the Python client:
host = craton.hosts.get(item_id=8)
host.variables.update(x='foo', y={'a': 47, 'b': True}, z='baz')
host.variables.delete("foo", "bar", "baz")
As well as for the CLI:
craton host-vars-get 1
craton host-vars-set 3 x=true y=47 z=foo/bar w=3.14159
cat <<EOF | craton host-vars-set 13
{
"glance_default_store": "not-so-swift",
"neutron_l2_population": false,
"make_stuff_up": true,
"some/namespaced/variable": {"a": 1, "b": 2}
}
EOF
craton --format json host-vars-get 13 | jq -C
craton host-vars-delete 13 make_stuff_up
craton host-vars-set 13 x= y=42 # deletes x
This patch implements the basis for supporting this
in other resources as well, however we only address
hosts here as an initial implementation. We will
fast-follow with support in other resources.
Partial-Bug: 1659110
Change-Id: Id30188937518d7103d6f943cf1d038b039dc30cc
68 lines
2.2 KiB
Python
68 lines
2.2 KiB
Python
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
# not use this file except in compliance with the License. You may obtain
|
|
# a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
# License for the specific language governing permissions and limitations
|
|
# under the License.
|
|
"""Tests for `cratonclient.v1.clouds` module."""
|
|
|
|
from cratonclient import crud
|
|
from cratonclient.tests import base
|
|
from cratonclient.v1 import variables
|
|
|
|
import mock
|
|
|
|
|
|
class TestVariables(base.TestCase):
|
|
"""Tests for the Cloud Resource."""
|
|
|
|
def setUp(self):
|
|
"""Basic test setup."""
|
|
super(TestVariables, self).setUp()
|
|
session = mock.Mock()
|
|
self.variable_mgr = variables.VariableManager(session, '')
|
|
|
|
def test_is_a_crudclient(self):
|
|
"""Verify our CloudManager is a CRUDClient."""
|
|
self.assertIsInstance(self.variable_mgr, crud.CRUDClient)
|
|
|
|
def test_variables_dict(self):
|
|
"""Assert Variables instantiation produces sane variables dict."""
|
|
test_data = {
|
|
"foo": "bar",
|
|
"zoo": {
|
|
"baz": "boo"
|
|
}
|
|
}
|
|
resource_obj = self.variable_mgr.resource_class(
|
|
mock.Mock(),
|
|
{"variables": test_data}
|
|
)
|
|
|
|
expected_variables_dict = {
|
|
"foo": variables.Variable("foo", "bar"),
|
|
"zoo": variables.Variable("zoo", {"baz": "boo"})
|
|
}
|
|
self.assertDictEqual(expected_variables_dict,
|
|
resource_obj._variables_dict)
|
|
|
|
def test_to_dict(self):
|
|
"""Assert Variables.to_dict() produces original variables dict."""
|
|
test_data = {
|
|
"foo": "bar",
|
|
"zoo": {
|
|
"baz": "boo"
|
|
}
|
|
}
|
|
resource_obj = self.variable_mgr.resource_class(
|
|
mock.Mock(),
|
|
{"variables": test_data}
|
|
)
|
|
|
|
self.assertDictEqual(test_data, resource_obj.to_dict())
|