Create resource for tests

This commit is contained in:
Dmitry Shulyak 2015-06-10 17:34:05 +03:00
parent 7eb941330d
commit 831ab2e08b
7 changed files with 39 additions and 23 deletions

1
.gitignore vendored
View File

@ -14,3 +14,4 @@ tmp/
state/
clients.json
rs/
x-venv/

View File

@ -170,7 +170,6 @@ def deploy():
signals.Connections.flush()
has_errors = False
for r in locals().values():
if not isinstance(r, resource.Resource):

View File

@ -20,7 +20,6 @@ pip install -r solar/requirements.txt --download-cache=/tmp/$JOB_NAME
pushd solar/solar
PYTHONPATH=$WORKSPACE/solar CONFIG_FILE=$CONFIG_FILE python test/test_signals.py
PYTHONPATH=$WORKSPACE/solar CONFIG_FILE=$CONFIG_FILE python test/test_validation.py
PYTHONPATH=$WORKSPACE/solar CONFIG_FILE=$CONFIG_FILE py.test test/
popd

View File

@ -26,7 +26,11 @@ class Resource(object):
self.metadata = metadata
self.actions = metadata.get('actions', {}).keys() or None
self.args = {}
self.set_args(args)
self.changed = []
self.tags = tags or []
def set_args(self, args):
for arg_name, arg_value in args.items():
if not self.metadata['input'].get(arg_name):
continue
@ -39,11 +43,9 @@ class Resource(object):
value = metadata_arg['value']
self.args[arg_name] = observer.create(type_, self, arg_name, value)
self.changed = []
self.tags = tags or []
def __repr__(self):
return ("Resource(name='{name}', metadata={metadata}, args={args}, "
return ("Resource(name='{id}', metadata={metadata}, args={input}, "
"tags={tags})").format(**self.to_dict())
def color_repr(self):
@ -51,8 +53,8 @@ class Resource(object):
arg_color = 'yellow'
return ("{resource_s}({name_s}='{name}', {metadata_s}={metadata}, "
"{args_s}={args}, {tags_s}={tags})").format(
return ("{resource_s}({name_s}='{id}', {metadata_s}={metadata}, "
"{args_s}={input}, {tags_s}={tags})").format(
resource_s=click.style('Resource', fg='white', bold=True),
name_s=click.style('name', fg=arg_color, bold=True),
metadata_s=click.style('metadata', fg=arg_color, bold=True),

View File

@ -26,14 +26,14 @@ class RedisDB(object):
def read(self, uid, collection=COLLECTIONS.resource):
try:
return json.loads(
self._r.get(self._make_key(collection.name, uid))
self._r.get(self._make_key(collection, uid))
)
except TypeError:
return None
def save(self, uid, data, collection=COLLECTIONS.resource):
return self._r.set(
self._make_key(collection.name, uid),
self._make_key(collection, uid),
json.dumps(data)
)
@ -41,7 +41,7 @@ class RedisDB(object):
return self._r.delete(self._make_key(collection, uid))
def get_list(self, collection=COLLECTIONS.resource):
key_glob = self._make_key(collection.name, '*')
key_glob = self._make_key(collection, '*')
for key in self._r.keys(key_glob):
yield json.loads(self._r.get(key))
@ -50,7 +50,7 @@ class RedisDB(object):
self._r.flushdb()
def _make_key(self, collection, _id):
return '{0}:{1}'.format(collection, _id)
return '{0}:{1}'.format(collection.name, _id)
class FakeRedisDB(RedisDB):

View File

@ -11,12 +11,17 @@ from solar import state
def default_resources():
from solar.core import signals
from solar.core import resource
node1 = resource.create('node1', '/vagrant/resources/ro_node/', {'ip': '10.0.0.3', 'ssh_key': '/vagrant/.vagrant/machines/solar-dev1/virtualbox/private_key', 'ssh_user': 'vagrant'})
rabbitmq_service1 = resource.create('rabbitmq', '/vagrant/resources/rabbitmq_service/', {'ssh_user': '', 'ip': '','management_port': '15672', 'port': '5672', 'ssh_key': '', 'container_name': 'rabbitmq_service1', 'image': 'rabbitmq:3-management'})
openstack_vhost = resource.create('vhost', '/vagrant/resources/rabbitmq_vhost/', {'ssh_user': '', 'ip': '', 'ssh_key': '', 'vhost_name': 'openstack', 'container_name': ''})
node1 = resource.wrap_resource(
{'id': 'node1',
'input': {'ip': {'value':'10.0.0.3'}}})
node1.save()
rabbitmq_service1 = resource.wrap_resource(
{'id':'rabbitmq', 'input': {
'ip' : {'value': ''},
'image': {'value': 'rabbitmq:3-management'}}})
rabbitmq_service1.save()
signals.connect(node1, rabbitmq_service1)
signals.connect(rabbitmq_service1, openstack_vhost)
return resource.load_all()
@ -25,7 +30,7 @@ def default_resources():
def test_changes_on_update_image(maction):
log = operations.stage_changes()
assert len(log) == 3
assert len(log) == 2
operations.commit_changes()

View File

@ -9,14 +9,24 @@ from solar import state
@pytest.fixture
def resources():
node1 = resource.create('node1', '/vagrant/resources/ro_node/', {'ip': '10.0.0.3', 'ssh_key': '/vagrant/', 'ssh_user': 'vagrant'})
mariadb_service1 = resource.create('mariadb', '/vagrant/resources/mariadb_service', {'image': 'mariadb', 'root_password': 'mariadb', 'port': 3306, 'ip': '', 'ssh_user': '', 'ssh_key': ''})
keystone_db = resource.create('keystone_db', '/vagrant/resources/mariadb_keystone_db/', {'db_name': 'keystone_db', 'login_password': '', 'login_user': 'root', 'login_port': '', 'ip': '', 'ssh_user': '', 'ssh_key': ''})
node1 = resource.wrap_resource(
{'id': 'node1',
'input': {'ip': {'value':'10.0.0.3'}}})
node1.save()
mariadb_service1 = resource.wrap_resource(
{'id':'mariadb', 'input': {
'port' : {'value': 3306},
'ip': {'value': ''}}})
mariadb_service1.save()
keystone_db = resource.wrap_resource(
{'id':'keystone_db',
'input': {
'login_port' : {'value': ''},
'ip': {'value': ''}}})
keystone_db.save()
signals.connect(node1, mariadb_service1)
signals.connect(node1, keystone_db)
signals.connect(mariadb_service1, keystone_db, {'root_password': 'login_password', 'port': 'login_port'})
signals.connect(mariadb_service1, keystone_db, {'port': 'login_port'})
return resource.load_all()