murano-conductor/tests/conductor/test_windows_agent.py
Georgy Okrokvertskhov 30b9bed2fc Added base64 encryption of the script files. Now script files are stored
separately from templates in the ./scripts/ directory.

test_windows_agent.py updated.

Formatting in windows_agent.py fixed.

Tracing and error capturing added to Set-LocalUserPassword.

Function Set-LocalUserPassword removed as it is implemented by workflow
means.

Scripts now stored in one common folder.
Scripts updated from murano-deployment.
Templates updated to reflect new script names.

Workflow template can reference multiple script files. These script
files will be concatinated and encrypted with base64.

Change-Id: Icb3532d2fb724bbb711c06086cb906bde22a380f

Fixed flake8 reported issues.

Change-Id: Icb3532d2fb724bbb711c06086cb906bde22a380f

Fixed test failure after reformatting.

Change-Id: Icb3532d2fb724bbb711c06086cb906bde22a380f

Fixed issues with test. Revert back path selection for scripts folder.
It is reasonable to have an ability to use own folder for custom
workflows so script path is relative to template location.

Change-Id: Icb3532d2fb724bbb711c06086cb906bde22a380f
2013-08-12 11:37:41 -07:00

64 lines
2.1 KiB
Python

# Copyright (c) 2013 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 unittest
import mock
import mockfs
import json
from muranoconductor.commands.windows_agent import WindowsAgentExecutor
class TestWindowsAgent(unittest.TestCase):
def setUp(self):
self.mfs = mockfs.replace_builtins()
self.template = {
"Scripts": [
"Get-DnsListeningIpAddress.ps1",
"Join-Domain.ps1"
],
"Commands": [
{
"Name": "Get-DnsListeningIpAddress",
"Arguments": {}
}],
"RebootOnCompletion": 0
}
self.mfs.add_entries({
'./data/templates/agent/test.template':
json.dumps(self.template),
'./data/templates/agent/scripts/Get-DnsListeningIpAddress.ps1':
'function GetDNSip(){\ntest\n}\n',
'./data/templates/agent/scripts/Join-Domain.ps1':
'function JoinDomain(){\ntest\n}\n',
})
self.template_path = './data/templates/agent/test.template'
def test_script_encode(self):
stack = mock.MagicMock()
rmqclient = mock.MagicMock()
reporter = mock.MagicMock()
rmqclient.declare = mock.Mock()
executor = WindowsAgentExecutor(stack, rmqclient, reporter)
result = executor.encode_scripts(self.template, self.template_path)
encoded = [
'ZnVuY3Rpb24gR2V0RE5TaXAoKXsKdGVzdAp9Cg==\n',
'ZnVuY3Rpb24gSm9pbkRvbWFpbigpewp0ZXN0Cn0K\n'
]
self.assertEqual(result['Scripts'], encoded,
'Encoded script is incorrect')