def _get_event_target(cluster_obj=None): if cluster_obj: target = resource.Resource(id=cluster_obj.uuid, name=cluster_obj.name, typeURI='service/magnum/cluster') target.add_attachment(attach_val=attachment.Attachment( typeURI='service/magnum/cluster', content={ 'status': cluster_obj.status, 'status_reason': cluster_obj.status_reason, 'project_id': cluster_obj.project_id, 'created_at': cluster_obj.created_at, 'updated_at': cluster_obj.updated_at, 'cluster_template_id': cluster_obj.cluster_template_id, 'keypair': cluster_obj.keypair, 'docker_volume_size:': cluster_obj.docker_volume_size, 'labels': cluster_obj.labels, 'master_flavor_id': cluster_obj.master_flavor_id, 'flavor_id': cluster_obj.flavor_id, 'stack_id': cluster_obj.stack_id, 'health_status': cluster_obj.health_status, 'create_timeout': cluster_obj.create_timeout, 'api_address': cluster_obj.api_address, 'discovery_url': cluster_obj.discovery_url, 'node_addresses': cluster_obj.node_addresses, 'master_addresses': cluster_obj.master_addresses, 'node_count': cluster_obj.node_count, 'master_count': cluster_obj.master_count, }, name='cluster_data')) return target return resource.Resource(typeURI='service/magnum/cluster')
def test_resource_shortform(self): res = resource.Resource(id='target') self.assertEqual(res.is_valid(), True) res.add_attachment(attachment.Attachment(typeURI='attachURI', content='content', name='attachment_name')) self.assertEqual(res.is_valid(), False)
def test_attachment(self): attach = attachment.Attachment(typeURI='attachURI', content='content', name='attachment_name') self.assertEqual(attach.is_valid(), True) dict_attach = attach.as_dict() for key in attachment.ATTACHMENT_KEYNAMES: self.assertIn(key, dict_attach)
def test_resource(self): res = resource.Resource(typeURI='storage', name='res_name', domain='res_domain', ref='res_ref', credential=credential.Credential( token=identifier.generate_uuid()), host=host.Host(address='192.168.0.1'), geolocation=geolocation.Geolocation(), geolocationId=identifier.generate_uuid()) res.add_attachment(attachment.Attachment(typeURI='attachURI', content='content', name='attachment_name')) res.add_address(endpoint.Endpoint(url='http://192.168.0.1')) self.assertEqual(res.is_valid(), True) dict_res = res.as_dict() for key in resource.RESOURCE_KEYNAMES: self.assertIn(key, dict_res)
def test_event(self): ev = event.Event(eventType='activity', id=identifier.generate_uuid(), eventTime=timestamp.get_utc_now(), initiator=resource.Resource(typeURI='storage'), initiatorId=identifier.generate_uuid(), action='read', target=resource.Resource(typeURI='storage'), targetId=identifier.generate_uuid(), observer=resource.Resource(id='target'), observerId=identifier.generate_uuid(), outcome='success', reason=reason.Reason(reasonType='HTTP', reasonCode='200'), severity='high') ev.add_measurement( measurement.Measurement(result='100', metricId=identifier.generate_uuid())), ev.add_tag(tag.generate_name_value_tag('name', 'val')) ev.add_attachment(attachment.Attachment(typeURI='attachURI', content='content', name='attachment_name')) ev.observer = resource.Resource(typeURI='service/security') ev.add_reporterstep(reporterstep.Reporterstep( role='observer', reporter=resource.Resource(typeURI='service/security'))) ev.add_reporterstep(reporterstep.Reporterstep( reporterId=identifier.generate_uuid())) self.assertEqual(ev.is_valid(), False) dict_ev = ev.as_dict() for key in event.EVENT_KEYNAMES: self.assertIn(key, dict_ev) ev = event.Event(eventType='activity', id=identifier.generate_uuid(), eventTime=timestamp.get_utc_now(), initiator=resource.Resource(typeURI='storage'), action='read', target=resource.Resource(typeURI='storage'), observer=resource.Resource(id='target'), outcome='success') self.assertEqual(ev.is_valid(), True) ev = event.Event(eventType='activity', id=identifier.generate_uuid(), eventTime=timestamp.get_utc_now(), initiatorId=identifier.generate_uuid(), action='read', targetId=identifier.generate_uuid(), observerId=identifier.generate_uuid(), outcome='success') self.assertEqual(ev.is_valid(), True) ev = event.Event(eventType='activity', id=identifier.generate_uuid(), eventTime=timestamp.get_utc_now(), initiator=resource.Resource(typeURI='storage'), action='read', targetId=identifier.generate_uuid(), observer=resource.Resource(id='target'), outcome='success') self.assertEqual(ev.is_valid(), True)