Extract deployment code and merge main and server
This commit is contained in:
@@ -6,11 +6,11 @@ deployment:
|
||||
flavor: shaker-flavor
|
||||
public_net: net04_ext
|
||||
private_net_cidr: 10.0.0.0/24
|
||||
agent_endpoint: 172.18.76.4:5998
|
||||
mode: pairs
|
||||
vm_count: 1
|
||||
vm_count: 2
|
||||
|
||||
tests:
|
||||
execution:
|
||||
nodes: [1, 2]
|
||||
tests:
|
||||
-
|
||||
class: netperf
|
||||
method: tcp_bidirectional
|
||||
|
||||
@@ -26,9 +26,9 @@ parameters:
|
||||
private_net_cidr:
|
||||
type: string
|
||||
description: Private network address (CIDR notation)
|
||||
agent_endpoint:
|
||||
server_endpoint:
|
||||
type: string
|
||||
description: Agent endpoint at shaker-queue-device
|
||||
description: Server endpoint address
|
||||
|
||||
resources:
|
||||
private_net:
|
||||
@@ -83,9 +83,9 @@ resources:
|
||||
str_replace:
|
||||
template: |
|
||||
#!/bin/sh
|
||||
shaker-agent --agent-endpoint=$AGENT_ENDPOINT --debug &
|
||||
shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug &
|
||||
params:
|
||||
"$AGENT_ENDPOINT": { get_param: agent_endpoint }
|
||||
"$SERVER_ENDPOINT": { get_param: server_endpoint }
|
||||
|
||||
{{ master.name }}_port:
|
||||
type: OS::Neutron::Port
|
||||
@@ -120,9 +120,9 @@ resources:
|
||||
str_replace:
|
||||
template: |
|
||||
#!/bin/sh
|
||||
shaker-agent --agent-endpoint=$AGENT_ENDPOINT --debug &
|
||||
shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug &
|
||||
params:
|
||||
"$AGENT_ENDPOINT": { get_param: agent_endpoint }
|
||||
"$SERVER_ENDPOINT": { get_param: server_endpoint }
|
||||
|
||||
{{ slave.name }}_port:
|
||||
type: OS::Neutron::Port
|
||||
|
||||
@@ -24,5 +24,5 @@ packages =
|
||||
|
||||
[entry_points]
|
||||
console_scripts =
|
||||
shaker = shaker.engine.main:main
|
||||
shaker = shaker.engine.server:main
|
||||
shaker-agent = shaker.agent.agent:main
|
||||
|
||||
@@ -35,6 +35,10 @@ OPTS = [
|
||||
cfg.StrOpt('scenario',
|
||||
required=True,
|
||||
help='Scenario file name'),
|
||||
|
||||
cfg.StrOpt('server-endpoint',
|
||||
required=True,
|
||||
help='Address for server connections (host:port)'),
|
||||
]
|
||||
|
||||
AGENT_OPTS = [
|
||||
@@ -44,9 +48,3 @@ AGENT_OPTS = [
|
||||
cfg.StrOpt('instance-id',
|
||||
help='The id of instance where agent is running'),
|
||||
]
|
||||
|
||||
SERVER_OPTS = [
|
||||
cfg.StrOpt('server-endpoint',
|
||||
required=True,
|
||||
help='Address for server connections (host:port)'),
|
||||
]
|
||||
|
||||
102
shaker/engine/deploy.py
Normal file
102
shaker/engine/deploy.py
Normal file
@@ -0,0 +1,102 @@
|
||||
# Copyright (c) 2015 Mirantis Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import uuid
|
||||
|
||||
import jinja2
|
||||
|
||||
from shaker.engine import heat
|
||||
from shaker.engine import keystone
|
||||
from shaker.engine import nova
|
||||
from shaker.engine import utils
|
||||
from shaker.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Deployment(object):
|
||||
def __init__(self, os_username, os_password, os_tenant_name, os_auth_url,
|
||||
server_endpoint):
|
||||
self.server_endpoint = server_endpoint
|
||||
keystone_kwargs = {'username': os_username,
|
||||
'password': os_password,
|
||||
'tenant_name': os_tenant_name,
|
||||
'auth_url': os_auth_url,
|
||||
}
|
||||
self.keystone_client = keystone.create_keystone_client(keystone_kwargs)
|
||||
self.heat_client = heat.create_heat_client(self.keystone_client)
|
||||
self.nova_client = nova.create_nova_client(keystone_kwargs)
|
||||
|
||||
def _get_compute_nodes(self):
|
||||
return [svc.host for svc in nova.get_compute_nodes(self.nova_client)]
|
||||
|
||||
def deploy(self, specification):
|
||||
vm_count = specification['vm_count']
|
||||
heat_template_name = specification['template']
|
||||
template_parameters = specification['template_parameters']
|
||||
|
||||
heat_template = utils.read_file(heat_template_name)
|
||||
compute_nodes = self._get_compute_nodes()
|
||||
|
||||
# prepare jinja template
|
||||
masters = []
|
||||
slaves = []
|
||||
for i in range(vm_count):
|
||||
masters.append(dict(name='master_%s' % i, node=compute_nodes[i]))
|
||||
slaves.append(dict(name='slave_%s' % i, node=compute_nodes[i]))
|
||||
|
||||
vars_values = {
|
||||
'masters': masters,
|
||||
'slaves': slaves,
|
||||
}
|
||||
|
||||
compiled_template = jinja2.Template(heat_template)
|
||||
rendered_template = compiled_template.render(vars_values)
|
||||
|
||||
LOG.info('Rendered template: %s', rendered_template)
|
||||
|
||||
template_parameters['private_net_name'] = 'net_%s' % uuid.uuid4()
|
||||
template_parameters['server_endpoint'] = self.server_endpoint
|
||||
|
||||
self.stack_name = 'shaker_%s' % uuid.uuid4()
|
||||
|
||||
stack_params = {
|
||||
'stack_name': self.stack_name,
|
||||
'parameters': template_parameters,
|
||||
'template': rendered_template,
|
||||
}
|
||||
|
||||
stack = self.heat_client.stacks.create(**stack_params)['stack']
|
||||
LOG.info('New stack: %s', stack)
|
||||
|
||||
heat.wait_stack_completion(self.heat_client, stack['id'])
|
||||
|
||||
outputs_list = self.heat_client.stacks.get(
|
||||
stack['id']).to_dict()['outputs']
|
||||
outputs = dict((item['output_key'], item) for item in outputs_list)
|
||||
|
||||
for i in range(vm_count):
|
||||
masters[i]['public_ip'] = (
|
||||
outputs[masters[i]['name'] + '_public_ip']['output_value'])
|
||||
slaves[i]['private_ip'] = (
|
||||
outputs[slaves[i]['name'] + '_private_ip']['output_value'])
|
||||
|
||||
LOG.info('Masters: %s', masters)
|
||||
LOG.info('Slaves: %s', slaves)
|
||||
|
||||
def cleanup(self):
|
||||
LOG.debug('Cleaning up the stack: %s', self.stack_name)
|
||||
self.heat_client.stacks.delete(self.stack_name)
|
||||
@@ -1,124 +0,0 @@
|
||||
# Copyright (c) 2015 Mirantis Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import uuid
|
||||
|
||||
import jinja2
|
||||
from oslo.config import cfg
|
||||
import yaml
|
||||
|
||||
from shaker.engine import config
|
||||
from shaker.engine import heat
|
||||
from shaker.engine import keystone
|
||||
from shaker.engine import nova
|
||||
from shaker.engine import utils
|
||||
from shaker.openstack.common import log as logging
|
||||
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def run():
|
||||
keystone_kwargs = {'username': cfg.CONF.os_username,
|
||||
'password': cfg.CONF.os_password,
|
||||
'tenant_name': cfg.CONF.os_tenant_name,
|
||||
'auth_url': cfg.CONF.os_auth_url,
|
||||
}
|
||||
keystone_client = keystone.create_keystone_client(keystone_kwargs)
|
||||
|
||||
heat_client = heat.create_heat_client(keystone_client)
|
||||
for stack in heat_client.stacks.list():
|
||||
LOG.info('Stacks: %s', stack)
|
||||
|
||||
nova_client = nova.create_nova_client(keystone_kwargs)
|
||||
compute_nodes = [svc.host for svc in nova.get_compute_nodes(nova_client)]
|
||||
LOG.info('Compute nodes: %s', compute_nodes)
|
||||
|
||||
scenario_raw = utils.read_file(cfg.CONF.scenario)
|
||||
|
||||
scenario = yaml.safe_load(scenario_raw)
|
||||
LOG.info('Scenario: %s', scenario)
|
||||
|
||||
mode = scenario['deployment']['mode']
|
||||
vm_count = scenario['deployment']['vm_count']
|
||||
heat_template_name = scenario['deployment']['template']
|
||||
template_parameters = scenario['deployment']['template_parameters']
|
||||
|
||||
heat_template = utils.read_file(heat_template_name)
|
||||
|
||||
if mode != 'pairs':
|
||||
return
|
||||
|
||||
# prepare jinja template
|
||||
masters = []
|
||||
slaves = []
|
||||
for i in range(vm_count):
|
||||
masters.append(dict(name='master%s' % i, node=compute_nodes[i]))
|
||||
slaves.append(dict(name='slave%s' % i, node=compute_nodes[i]))
|
||||
|
||||
vars_values = {
|
||||
'masters': masters,
|
||||
'slaves': slaves,
|
||||
}
|
||||
|
||||
compiled_template = jinja2.Template(heat_template)
|
||||
rendered_template = compiled_template.render(vars_values)
|
||||
|
||||
LOG.info('Rendered template: %s', rendered_template)
|
||||
|
||||
template_parameters['private_net_name'] = 'net_%s' % uuid.uuid4()
|
||||
|
||||
stack_name = 'shaker_%s' % uuid.uuid4()
|
||||
|
||||
stack_params = {
|
||||
'stack_name': stack_name,
|
||||
'parameters': template_parameters,
|
||||
'template': rendered_template,
|
||||
}
|
||||
stack = heat_client.stacks.create(**stack_params)['stack']
|
||||
LOG.info('New stack: %s', stack)
|
||||
|
||||
heat.wait_stack_completion(heat_client, stack['id'])
|
||||
|
||||
outputs_list = heat_client.stacks.get(stack['id']).to_dict()['outputs']
|
||||
outputs = dict((item['output_key'], item) for item in outputs_list)
|
||||
|
||||
for i in range(vm_count):
|
||||
masters[i]['public_ip'] = (outputs[masters[i]['name'] + '_public_ip']
|
||||
['output_value'])
|
||||
slaves[i]['private_ip'] = (outputs[slaves[i]['name'] + '_private_ip']
|
||||
['output_value'])
|
||||
|
||||
LOG.info('Masters: %s', masters)
|
||||
LOG.info('Slaves: %s', slaves)
|
||||
|
||||
# wait for ssh to nodes
|
||||
|
||||
|
||||
def main():
|
||||
# init conf and logging
|
||||
conf = cfg.CONF
|
||||
conf.register_cli_opts(config.OPTS)
|
||||
conf.register_opts(config.OPTS)
|
||||
conf(project='shaker')
|
||||
|
||||
logging.setup('shaker')
|
||||
LOG.info('Logging enabled')
|
||||
|
||||
run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -16,9 +16,11 @@
|
||||
import time
|
||||
|
||||
from oslo.config import cfg
|
||||
import yaml
|
||||
import zmq
|
||||
|
||||
from shaker.engine import config
|
||||
from shaker.engine import deploy
|
||||
from shaker.engine import utils
|
||||
from shaker.openstack.common import log as logging
|
||||
|
||||
@@ -155,11 +157,23 @@ def run(message_queue):
|
||||
LOG.info('Done')
|
||||
|
||||
|
||||
def read_scenario():
|
||||
scenario_raw = utils.read_file(cfg.CONF.scenario)
|
||||
scenario = yaml.safe_load(scenario_raw)
|
||||
LOG.debug('Scenario: %s', scenario)
|
||||
return scenario
|
||||
|
||||
|
||||
def execute(execution):
|
||||
message_queue = MessageQueue(cfg.CONF.server_endpoint)
|
||||
run(message_queue)
|
||||
|
||||
|
||||
def main():
|
||||
# init conf and logging
|
||||
conf = cfg.CONF
|
||||
conf.register_cli_opts(config.SERVER_OPTS)
|
||||
conf.register_opts(config.SERVER_OPTS)
|
||||
conf.register_cli_opts(config.OPTS)
|
||||
conf.register_opts(config.OPTS)
|
||||
|
||||
try:
|
||||
conf(project='shaker')
|
||||
@@ -171,8 +185,15 @@ def main():
|
||||
logging.setup('shaker')
|
||||
LOG.info('Logging enabled')
|
||||
|
||||
message_queue = MessageQueue(cfg.CONF.server_endpoint)
|
||||
run(message_queue)
|
||||
scenario = read_scenario()
|
||||
deployment = deploy.Deployment(cfg.CONF.os_username,
|
||||
cfg.CONF.os_password,
|
||||
cfg.CONF.os_tenant_name,
|
||||
cfg.CONF.os_auth_url,
|
||||
cfg.CONF.server_endpoint)
|
||||
deployment.deploy(scenario['deployment'])
|
||||
execute(scenario['execution'])
|
||||
deployment.cleanup()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user