Push agent_id from the deployment engine

Parameter 'agent_id' is made required for agent

Change-Id: I9ca1fbde6280f19612eafb7085d794e27abaa831
This commit is contained in:
Ilya Shakhat 2015-03-03 13:13:14 +03:00
parent 3e9e4fcb51
commit ecbe78c989
9 changed files with 63 additions and 95 deletions

View File

@ -55,8 +55,8 @@
# From shaker.engine.config
#
# The id of instance where agent is running (string value)
#instance_id = <None>
# Agent unique id (string value)
#agent_id = <None>
#
# From shaker.openstack.common.log

View File

@ -1,8 +1,8 @@
heat_template_version: 2013-05-23
description: >
HOT template to create a new neutron network plus a router to the external
network, and for deploying servers into the new network.
description:
HOT template creates a new neutron network, a router to the external
network and plugs servers into this new network.
parameters:
image:
@ -14,12 +14,6 @@ parameters:
external_net:
type: string
description: ID or name of external network
private_net_name:
type: string
description: Name of private network to be created
private_net_cidr:
type: string
description: Private network address (CIDR notation)
server_endpoint:
type: string
description: Server endpoint address
@ -28,13 +22,13 @@ resources:
private_net:
type: OS::Neutron::Net
properties:
name: { get_param: private_net_name }
name: {{ unique }}_net
private_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: private_net }
cidr: { get_param: private_net_cidr }
cidr: 10.0.0.0/16
dns_nameservers: [ 8.8.8.8, 8.8.4.4 ]
router:
@ -52,7 +46,6 @@ resources:
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: shaker_vm_access
rules: [
{remote_ip_prefix: 0.0.0.0/0,
protocol: tcp,
@ -81,9 +74,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.master.name }}
{{ group.master.name }}_port:
type: OS::Neutron::Port
@ -107,9 +101,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.slave.name }}
{{ group.slave.name }}_port:
type: OS::Neutron::Port
@ -124,11 +119,11 @@ resources:
outputs:
{% for group in groups %}
{{ group.master.name }}_ip:
value: { get_attr: [ {{ group.master.name }}, networks, { get_param: private_net_name }, 0 ] }
value: { get_attr: [ {{ group.master.name }}, networks, { get_attr: [private_net, name] }, 0 ] }
{{ group.master.name }}_instance_name:
value: { get_attr: [ {{ group.master.name }}, instance_name ] }
{{ group.slave.name }}_ip:
value: { get_attr: [ {{ group.slave.name }}, networks, { get_param: private_net_name }, 0 ] }
value: { get_attr: [ {{ group.slave.name }}, networks, { get_attr: [private_net, name] }, 0 ] }
{{ group.slave.name }}_instance_name:
value: { get_attr: [ {{ group.slave.name }}, instance_name ] }
{% endfor %}

View File

@ -1,10 +1,8 @@
heat_template_version: 2013-05-23
description: >
HOT template to create a new neutron network plus a router to the public
network, and for deploying servers into the new network. The template also
assigns floating IP addresses to each server so they are routable from the
public network.
description:
HOT template creates a pair of networks plugged into the same router. Master VMs
and slave VMs are plugged into different networks.
parameters:
image:
@ -16,12 +14,6 @@ parameters:
external_net:
type: string
description: ID or name of external network for which floating IP addresses will be allocated
private_net_name:
type: string
description: Name of private network to be created
private_net_cidr:
type: string
description: Private network address (CIDR notation)
server_endpoint:
type: string
description: Server endpoint address
@ -30,7 +22,7 @@ resources:
east_private_net:
type: OS::Neutron::Net
properties:
name: east_private_net_name
name: {{ unique }}_net_east
east_private_subnet:
type: OS::Neutron::Subnet
@ -54,7 +46,7 @@ resources:
west_private_net:
type: OS::Neutron::Net
properties:
name: west_private_net_name
name: {{ unique }}_net_west
west_private_subnet:
type: OS::Neutron::Subnet
@ -72,7 +64,6 @@ resources:
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: shaker_vm_access
rules: [
{remote_ip_prefix: 0.0.0.0/0,
protocol: tcp,
@ -101,9 +92,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.master.name }}
{{ group.master.name }}_port:
type: OS::Neutron::Port
@ -127,9 +119,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.slave.name }}
{{ group.slave.name }}_port:
type: OS::Neutron::Port
@ -144,11 +137,11 @@ resources:
outputs:
{% for group in groups %}
{{ group.master.name }}_ip:
value: { get_attr: [ {{ group.master.name }}, networks, east_private_net_name, 0 ] }
value: { get_attr: [ {{ group.master.name }}, networks, { get_attr: [east_private_net, name] }, 0 ] }
{{ group.master.name }}_instance_name:
value: { get_attr: [ {{ group.master.name }}, instance_name ] }
{{ group.slave.name }}_ip:
value: { get_attr: [ {{ group.slave.name }}, networks, west_private_net_name, 0 ] }
value: { get_attr: [ {{ group.slave.name }}, networks, { get_attr: [west_private_net, name] }, 0 ] }
{{ group.slave.name }}_instance_name:
value: { get_attr: [ {{ group.slave.name }}, instance_name ] }
{% endfor %}

View File

@ -16,12 +16,6 @@ parameters:
external_net:
type: string
description: ID or name of external network for which floating IP addresses will be allocated
private_net_name:
type: string
description: Name of private network to be created
private_net_cidr:
type: string
description: Private network address (CIDR notation)
server_endpoint:
type: string
description: Server endpoint address
@ -30,7 +24,7 @@ resources:
north_private_net:
type: OS::Neutron::Net
properties:
name: north_private_net_name
name: {{ unique }}_net_north
north_private_subnet:
type: OS::Neutron::Subnet
@ -54,7 +48,7 @@ resources:
south_private_net:
type: OS::Neutron::Net
properties:
name: south_private_net_name
name: {{ unique }}_net_south
south_private_subnet:
type: OS::Neutron::Subnet
@ -78,7 +72,6 @@ resources:
server_security_group:
type: OS::Neutron::SecurityGroup
properties:
name: shaker_vm_access
rules: [
{remote_ip_prefix: 0.0.0.0/0,
protocol: tcp,
@ -107,9 +100,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.slave.name }}
{{ group.master.name }}_port:
type: OS::Neutron::Port
@ -133,9 +127,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.slave.name }}
{{ group.slave.name }}_port:
type: OS::Neutron::Port
@ -156,7 +151,7 @@ resources:
outputs:
{% for group in groups %}
{{ group.master.name }}_ip:
value: { get_attr: [ {{ group.master.name }}, networks, north_private_net, 0 ] }
value: { get_attr: [ {{ group.master.name }}, networks, { get_attr: [north_private_net, name] }, 0 ] }
{{ group.master.name }}_instance_name:
value: { get_attr: [ {{ group.master.name }}, instance_name ] }
{{ group.slave.name }}_ip:

View File

@ -13,14 +13,7 @@ parameters:
description: Flavor to use for servers
external_net:
type: string
description: >
ID or name of public network for which floating IP addresses will be allocated
private_net_name:
type: string
description: Name of private network to be created
private_net_cidr:
type: string
description: Private network address (CIDR notation)
description: ID or name of public network for which floating IP addresses will be allocated
server_endpoint:
type: string
description: Server endpoint address
@ -29,13 +22,13 @@ resources:
private_net:
type: OS::Neutron::Net
properties:
name: { get_param: private_net_name }
name: {{ unique }}_net
private_subnet:
type: OS::Neutron::Subnet
properties:
network_id: { get_resource: private_net }
cidr: { get_param: private_net_cidr }
cidr: 10.0.0.0/16
dns_nameservers: [ 8.8.8.8, 8.8.4.4 ]
router:
@ -66,9 +59,10 @@ resources:
str_replace:
template: |
#!/bin/sh
screen -dmS shaker-agent shaker-agent --server-endpoint=$SERVER_ENDPOINT --debug
screen -dmS shaker-agent-screen shaker-agent --server-endpoint=$SERVER_ENDPOINT --agent-id=$AGENT_ID
params:
"$SERVER_ENDPOINT": { get_param: server_endpoint }
"$AGENT_ID": {{ group.slave.name }}
{{ group.master.name }}_port:
type: OS::Neutron::Port
@ -82,7 +76,7 @@ resources:
outputs:
{% for group in groups %}
{{ group.master.name }}_ip:
value: { get_attr: [ {{ group.master.name }}, networks, private_net, 0 ] }
value: { get_attr: [ {{ group.master.name }}, networks, { get_attr: [private_net, name] }, 0 ] }
{{ group.master.name }}_instance_name:
value: { get_attr: [ {{ group.master.name }}, instance_name ] }
{% endfor %}

View File

@ -21,24 +21,16 @@ from oslo_config import cfg
import zmq
from shaker.engine import config
from shaker.engine import utils
from shaker.openstack.common import log as logging
LOG = logging.getLogger(__name__)
INSTANCE_ID_URI = 'http://169.254.169.254/2009-04-04/meta-data/instance-id'
def get_instance_id():
return utils.read_uri(INSTANCE_ID_URI)
def poll_task(socket, instance_id):
def poll_task(socket, agent_id):
payload = {
'operation': 'poll',
'agent_id': instance_id,
'agent_id': agent_id,
}
LOG.debug('Polling task: %s', payload)
socket.send_json(payload)
@ -47,10 +39,10 @@ def poll_task(socket, instance_id):
return res
def send_reply(socket, instance_id, result):
def send_reply(socket, agent_id, result):
message = {
'operation': 'reply',
'agent_id': instance_id,
'agent_id': agent_id,
}
message.update(result)
@ -81,8 +73,8 @@ def main():
endpoint = cfg.CONF.server_endpoint
instance_id = cfg.CONF.instance_id or get_instance_id()
LOG.info('My instance id is: %s', instance_id)
agent_id = cfg.CONF.agent_id
LOG.info('My instance id is: %s', agent_id)
context = zmq.Context()
LOG.info('Connecting to server: %s', endpoint)
@ -92,7 +84,7 @@ def main():
try:
while True:
task = poll_task(socket, instance_id)
task = poll_task(socket, agent_id)
if task['operation'] == 'execute':
now = int(time.time())
@ -105,7 +97,7 @@ def main():
# do something useful
command_stdout, command_stderr = processutils.execute(
*shlex.split(command))
send_reply(socket, instance_id, {
send_reply(socket, agent_id, {
'stdout': command_stdout,
'stderr': command_stderr,
})

View File

@ -71,8 +71,9 @@ SERVER_OPTS = [
]
AGENT_OPTS = [
cfg.StrOpt('instance-id',
help='The id of instance where agent is running'),
cfg.StrOpt('agent-id',
required=True,
help='Agent unique id'),
]

View File

@ -13,8 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import uuid
import jinja2
from shaker.engine import utils
@ -44,7 +42,7 @@ class Deployment(object):
self.flavor_name = flavor_name
self.image_name = image_name
self.stack_name = 'shaker_%s' % uuid.uuid4()
self.stack_name = 'shaker_%s' % utils.random_string()
self.stack_deployed = False
def _make_groups(self, vm_accommodation):
@ -59,8 +57,9 @@ class Deployment(object):
groups = []
for i in range(iterations):
group = dict(master=dict(name='master_%s' % i),
slave=dict(name='slave_%s' % i))
group = dict(
master=dict(name=('%s_master_%s' % (self.stack_name, i))),
slave=dict(name=('%s_slave_%s' % (self.stack_name, i))))
if 'pair' in vm_accommodation:
if 'single_room' in vm_accommodation:
@ -87,9 +86,6 @@ class Deployment(object):
result[param] = o
return result
def convert_instance_name_to_agent_id(self, instance_name):
return 'i-%s' % instance_name.split('-')[1]
def _make_agents(self, groups, outputs):
agents = []
@ -100,14 +96,13 @@ class Deployment(object):
LOG.info('Group is not deployed: %s. Ignoring', group)
continue
master.update(dict(mode='master',
id=self.convert_instance_name_to_agent_id(
master['instance_name'])))
master.update(group['master'])
master.update(dict(mode='master', id=group['master']['name']))
slave = self._get_outputs(outputs, group['slave']['name'],
['ip', 'instance_name'])
# todo workaround of Nova bug 1422686
# workaround of Nova bug 1422686
if slave.get('instance_name') and not slave.get('ip'):
LOG.info('Ignoring group because of missing IP: %s', group)
continue
@ -116,9 +111,8 @@ class Deployment(object):
if slave.get('instance_name'):
# slave is deployed
slave.update(dict(mode='slave',
id=self.convert_instance_name_to_agent_id(
slave['instance_name'])))
slave.update(group['slave'])
slave.update(dict(mode='slave', id=group['slave']['name']))
master['slave_id'] = slave['id']
slave['master_id'] = master['id']
@ -132,6 +126,7 @@ class Deployment(object):
# render template by jinja
vars_values = {
'groups': groups,
'unique': self.stack_name,
}
heat_template = utils.read_file(specification['template'])
compiled_template = jinja2.Template(heat_template)
@ -140,8 +135,6 @@ class Deployment(object):
# create stack by Heat
merged_parameters = {
'private_net_name': 'net_%s' % uuid.uuid4(),
'private_net_cidr': '10.0.0.0/16',
'server_endpoint': self.server_endpoint,
'external_net': self.external_net,
'image': self.image_name,

View File

@ -14,6 +14,7 @@
# limitations under the License.
import os
import random
import six
@ -58,3 +59,7 @@ def read_uri(uri):
except Exception as e:
LOG.warn('Error "%(error)s" while reading uri %(uri)s',
{'error': e, 'uri': uri})
def random_string(length=6):
return ''.join(random.sample('adefikmoprstuz', length))