Add tests and example template for atomic hook

Atomic hook can be used with bootconfig to deply containers using
atomic tool in rhel 7.1. This patch adds test and exmaple template
for the hook.

Change-Id: I0f2469225027f3d37c7dd59f85dee8b5aa24a874
This commit is contained in:
Rabi Mishra 2015-03-21 09:31:28 +05:30
parent d26e55b800
commit 637e6d569f
4 changed files with 185 additions and 0 deletions

View File

@ -0,0 +1,68 @@
heat_template_version: 2014-10-16
description: >
A template which demonstrates doing boot-time deployment of docker
container with atomic tool.
This template expects to be created with an environment which defines
the resource type Heat::InstallConfigAgent such as
../boot-config/container_agent_env.yaml
parameters:
key_name:
type: string
default: heat_key
flavor:
type: string
default: m1.small
image:
type: string
default: rhel-atomic
private_net:
type: string
default: private
public_net:
type: string
default: public
resources:
atomic_install_config:
type: OS::Heat::StructuredConfig
properties:
group: atomic
config:
command: install
image: imain/atomic-install-rabbitmq
atomic_install_deployment:
type: OS::Heat::StructuredDeployment
properties:
name: atomic_deployment
config:
get_resource: atomic_install_config
server:
get_resource: server
boot_config:
type: Heat::InstallConfigAgent
server:
type: OS::Nova::Server
properties:
image: {get_param: image}
flavor: {get_param: flavor}
key_name: {get_param: key_name}
networks:
- network: {get_param: private_net}
user_data_format: SOFTWARE_CONFIG
user_data: {get_attr: [boot_config, config]}
outputs:
result:
value:
get_attr: [atomic_install_deployment, result]
stdout:
value:
get_attr: [atomic_install_deployment, deploy_stdout]
stderr:
value:
get_attr: [atomic_install_deployment, deploy_stderr]
status_code:
value:
get_attr: [atomic_install_deployment, deploy_status_code]

View File

@ -0,0 +1,2 @@
resource_registry:
"Heat::InstallConfigAgent": ../boot-config/templates/install_container_agent.yaml

View File

View File

@ -0,0 +1,115 @@
#
# 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 json
import os
import fixtures
from tests.software_config import common
class HookAtomicTest(common.RunScriptTest):
data = {
"id": "abcdef001",
"group": "atomic",
"inputs": [],
"config": {
"command": "install",
"image": "imain/atomic-install-rabbitmq"
}
}
def setUp(self):
super(HookAtomicTest, self).setUp()
self.hook_path = self.relative_path(
__file__,
'../..',
'hot/software-config/heat-container-agent',
'scripts/hooks/atomic')
self.fake_tool_path = self.relative_path(
__file__,
'config-tool-fake.py')
self.working_dir = self.useFixture(fixtures.TempDir())
self.outputs_dir = self.useFixture(fixtures.TempDir())
self.test_state_path = self.outputs_dir.join('test_state.json')
self.env = os.environ.copy()
self.env.update({
'HEAT_ATOMIC_WORKING': self.working_dir.join(),
'HEAT_ATOMIC_CMD': self.fake_tool_path,
'TEST_STATE_PATH': self.test_state_path,
})
def test_hook(self):
self.env.update({
'TEST_RESPONSE': json.dumps({
'stdout': 'Downloading xxx',
'stderr': ''
})
})
returncode, stdout, stderr = self.run_cmd(
[self.hook_path], self.env, json.dumps(self.data))
self.assertEqual(0, returncode, stderr)
self.assertEqual({
'deploy_stdout': 'Downloading xxx',
'deploy_stderr': '',
'deploy_status_code': 0
}, json.loads(stdout))
state = self.json_from_file(self.test_state_path)
self.assertEqual(
[
self.fake_tool_path,
'install',
'imain/atomic-install-rabbitmq',
'-n abcdef001',
''
],
state['args'])
def test_hook_failed(self):
self.env.update({
'TEST_RESPONSE': json.dumps({
'stdout': '',
'stderr': 'Container exists...',
'returncode': 1
})
})
returncode, stdout, stderr = self.run_cmd(
[self.hook_path], self.env, json.dumps(self.data))
self.assertEqual(0, returncode, stderr)
self.assertEqual({
'deploy_stdout': '',
'deploy_stderr': 'Container exists...',
'deploy_status_code': 1
}, json.loads(stdout))
state = self.json_from_file(self.test_state_path)
self.assertEqual(
[
self.fake_tool_path,
'install',
'imain/atomic-install-rabbitmq',
'-n abcdef001',
''
],
state['args'])