summaryrefslogtreecommitdiffstats
path: root/doctor_tests/installer/common/set_config.py
diff options
context:
space:
mode:
authorTomi Juvonen <tomi.juvonen@nokia.com>2018-09-28 12:15:43 +0300
committerTomi Juvonen <tomi.juvonen@nokia.com>2018-10-29 12:52:57 +0000
commit9e012b87f560fe13f8cc63a21321a4f0c2efa1b0 (patch)
tree5f70c3f4309d13a9fc217e404e2680ac847220cb /doctor_tests/installer/common/set_config.py
parenta7517dda9ede8bedadcbcedf7a46187268977d3a (diff)
Support Apex with services in containers
Upstream apex now works in containers, so if used, it needs to be supported JIRA: DOCTOR-130 Change-Id: I3d73a1699e4fee53b001f043f55d0eeefa7bfb7b Signed-off-by: Tomi Juvonen <tomi.juvonen@nokia.com> (cherry picked from commit a6575910a137f8932e294f66c9da3194ad937691)
Diffstat (limited to 'doctor_tests/installer/common/set_config.py')
-rw-r--r--doctor_tests/installer/common/set_config.py135
1 files changed, 79 insertions, 56 deletions
diff --git a/doctor_tests/installer/common/set_config.py b/doctor_tests/installer/common/set_config.py
index 42465247..3dc6cd9a 100644
--- a/doctor_tests/installer/common/set_config.py
+++ b/doctor_tests/installer/common/set_config.py
@@ -10,12 +10,16 @@ import os
import shutil
import yaml
-ep_file = '/etc/ceilometer/event_pipeline.yaml'
-ep_file_bak = '/etc/ceilometer/event_pipeline.yaml.bak'
-event_notifier_topic = 'notifier://?topic=alarm.all'
+
+cbase = "/var/lib/config-data/puppet-generated/ceilometer"
+if not os.path.isdir(cbase):
+ cbase = ""
def set_notifier_topic():
+ ep_file = cbase + '/etc/ceilometer/event_pipeline.yaml'
+ ep_file_bak = cbase + '/etc/ceilometer/event_pipeline.yaml.bak'
+ event_notifier_topic = 'notifier://?topic=alarm.all'
config_modified = False
if not os.path.isfile(ep_file):
@@ -42,24 +46,77 @@ def set_notifier_topic():
file.write(yaml.safe_dump(config))
-def set_maintenance_event_definitions():
- ed_file = '/etc/ceilometer/event_definitions.yaml'
- ed_file_bak = '/etc/ceilometer/event_definitions.bak'
+def set_event_definitions():
+ ed_file = cbase + '/etc/ceilometer/event_definitions.yaml'
+ ed_file_bak = cbase + '/etc/ceilometer/event_definitions.bak'
+ orig_ed_file_exist = True
+ modify_config = False
if not os.path.isfile(ed_file):
- raise Exception("File doesn't exist: %s." % ed_file)
-
- with open(ed_file, 'r') as file:
- config = yaml.safe_load(file)
+ # Deployment did not modify file, so it did not exist
+ src_file = '/etc/ceilometer/event_definitions.yaml'
+ if not os.path.isfile(src_file):
+ config = []
+ orig_ed_file_exist = False
+ else:
+ shutil.copyfile('/etc/ceilometer/event_definitions.yaml', ed_file)
+ if orig_ed_file_exist:
+ with open(ed_file, 'r') as file:
+ config = yaml.safe_load(file)
et_list = [et['event_type'] for et in config]
+ if 'compute.instance.update' in et_list:
+ print('NOTE: compute.instance.update allready configured')
+ else:
+ print('NOTE: add compute.instance.update to event_definitions.yaml')
+ modify_config = True
+ instance_update = {
+ 'event_type': 'compute.instance.update',
+ 'traits': {
+ 'deleted_at': {'fields': 'payload.deleted_at',
+ 'type': 'datetime'},
+ 'disk_gb': {'fields': 'payload.disk_gb',
+ 'type': 'int'},
+ 'display_name': {'fields': 'payload.display_name'},
+ 'ephemeral_gb': {'fields': 'payload.ephemeral_gb',
+ 'type': 'int'},
+ 'host': {'fields': 'publisher_id.`split(., 1, 1)`'},
+ 'instance_id': {'fields': 'payload.instance_id'},
+ 'instance_type': {'fields': 'payload.instance_type'},
+ 'instance_type_id': {'fields': 'payload.instance_type_id',
+ 'type': 'int'},
+ 'launched_at': {'fields': 'payload.launched_at',
+ 'type': 'datetime'},
+ 'memory_mb': {'fields': 'payload.memory_mb',
+ 'type': 'int'},
+ 'old_state': {'fields': 'payload.old_state'},
+ 'os_architecture': {
+ 'fields':
+ "payload.image_meta.'org.openstack__1__architecture'"},
+ 'os_distro': {
+ 'fields':
+ "payload.image_meta.'org.openstack__1__os_distro'"},
+ 'os_version': {
+ 'fields':
+ "payload.image_meta.'org.openstack__1__os_version'"},
+ 'resource_id': {'fields': 'payload.instance_id'},
+ 'root_gb': {'fields': 'payload.root_gb',
+ 'type': 'int'},
+ 'service': {'fields': 'publisher_id.`split(., 0, -1)`'},
+ 'state': {'fields': 'payload.state'},
+ 'tenant_id': {'fields': 'payload.tenant_id'},
+ 'user_id': {'fields': 'payload.user_id'},
+ 'vcpus': {'fields': 'payload.vcpus', 'type': 'int'}
+ }
+ }
+ config.append(instance_update)
+
if 'maintenance.scheduled' in et_list:
- add_mscheduled = False
print('NOTE: maintenance.scheduled allready configured')
else:
print('NOTE: add maintenance.scheduled to event_definitions.yaml')
- add_mscheduled = True
+ modify_config = True
mscheduled = {
'event_type': 'maintenance.scheduled',
'traits': {
@@ -72,16 +129,15 @@ def set_maintenance_event_definitions():
'session_id': {'fields': 'payload.session_id'},
'project_id': {'fields': 'payload.project_id'},
'metadata': {'fields': 'payload.metadata'}
+ }
}
- }
config.append(mscheduled)
if 'maintenance.host' in et_list:
- add_mhost = False
print('NOTE: maintenance.host allready configured')
else:
print('NOTE: add maintenance.host to event_definitions.yaml')
- add_mhost = True
+ modify_config = True
mhost = {
'event_type': 'maintenance.host',
'traits': {
@@ -89,51 +145,18 @@ def set_maintenance_event_definitions():
'project_id': {'fields': 'payload.project_id'},
'state': {'fields': 'payload.state'},
'session_id': {'fields': 'payload.session_id'}
+ }
}
- }
config.append(mhost)
- if add_mscheduled or add_mhost:
- shutil.copyfile(ed_file, ed_file_bak)
+ if modify_config:
+ if orig_ed_file_exist:
+ shutil.copyfile(ed_file, ed_file_bak)
+ else:
+ with open(ed_file_bak, 'w+') as file:
+ file.close()
with open(ed_file, 'w+') as file:
file.write(yaml.safe_dump(config))
-
-def set_cpu_allocation_ratio():
- nova_file = '/etc/nova/nova.conf'
- nova_file_bak = '/etc/nova/nova.bak'
-
- if not os.path.isfile(nova_file):
- raise Exception("File doesn't exist: %s." % nova_file)
- # TODO (tojuvone): Unfortunately ConfigParser did not produce working conf
- fcheck = open(nova_file)
- found_list = ([ca for ca in fcheck.readlines() if "cpu_allocation_ratio"
- in ca])
- fcheck.close()
- if found_list and len(found_list):
- change = False
- found = False
- for car in found_list:
- if car.startswith('#'):
- continue
- if car.startswith('cpu_allocation_ratio'):
- found = True
- if "1.0" not in car.split('=')[1]:
- change = True
- if not found or change:
- # need to add or change
- shutil.copyfile(nova_file, nova_file_bak)
- fin = open(nova_file_bak)
- fout = open(nova_file, "wt")
- for line in fin:
- if change and line.startswith("cpu_allocation_ratio"):
- line = "cpu_allocation_ratio=1.0"
- if not found and line.startswith("[DEFAULT]"):
- line += "cpu_allocation_ratio=1.0\n"
- fout.write(line)
- fin.close()
- fout.close()
-
set_notifier_topic()
-set_maintenance_event_definitions()
-set_cpu_allocation_ratio()
+set_event_definitions()