aboutsummaryrefslogtreecommitdiffstats
path: root/app/test/utils/test_cli_dist_translator.py
blob: e6a808043397baa6edda8960ed49733337d017ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
###############################################################################
# Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems)   #
# and others                                                                  #
#                                                                             #
# All rights reserved. This program and the accompanying materials            #
# are made available under the terms of the Apache License, Version 2.0       #
# which accompanies this distribution, and is available at                    #
# http://www.apache.org/licenses/LICENSE-2.0                                  #
###############################################################################
import unittest

from utils.cli_dist_translator import CliDistTranslator


class TestCliDistTranslator(unittest.TestCase):

    MERCURY_DIST = 'Mercury'
    MERCURY_VER = '10239'

    SOURCE_TEXT = 'some text'
    IP_LINK_TEXT = 'ip link show'
    IP_LINK_TRANSLATED_MERCURY = \
        'docker exec --user root ovs_vswitch_10239 ip link show'

    def test_unknown_dist(self):
        translator = CliDistTranslator('UNKNOWN')
        result = translator.translate(self.SOURCE_TEXT)
        self.assertEqual(result, self.SOURCE_TEXT,
                         'unknown dist should not cause translation')

    def test_mercury_dist(self):
        translator = CliDistTranslator(self.MERCURY_DIST, self.MERCURY_VER)
        result = translator.translate(self.SOURCE_TEXT)
        self.assertEqual(result, self.SOURCE_TEXT,
                         'known dist should not translate unrelated texts')
        result = translator.translate(self.IP_LINK_TEXT)
        self.assertEqual(result, self.IP_LINK_TRANSLATED_MERCURY,
                         'incorrect translation of command for mercury dist')
-Scalar l-Scalar-Plain">ctlplane # allows undercloud to config endpoints KeystonePublicApiNetwork: internal_api ManilaApiNetwork: internal_api NeutronApiNetwork: internal_api HeatApiNetwork: internal_api HeatApiCfnNetwork: internal_api HeatApiCloudwatchNetwork: internal_api NovaApiNetwork: internal_api NovaMetadataNetwork: internal_api NovaVncProxyNetwork: internal_api SwiftStorageNetwork: storage_mgmt SwiftProxyNetwork: storage SaharaApiNetwork: internal_api HorizonNetwork: internal_api MemcachedNetwork: internal_api RabbitmqNetwork: internal_api RedisNetwork: internal_api MysqlNetwork: internal_api CephClusterNetwork: storage_mgmt CephMonNetwork: storage CephRgwNetwork: storage PublicNetwork: external OpendaylightApiNetwork: internal_api OvnDbsNetwork: internal_api MistralApiNetwork: internal_api ZaqarApiNetwork: internal_api # We special-case the default ResolveNetwork for the CephStorage role # for backwards compatibility, all other roles default to internal_api CephStorageHostnameResolveNetwork: storage {% for role in roles if role.name != 'CephStorage' %} {{role.name}}HostnameResolveNetwork: internal_api {% endfor %} description: Mapping of service_name -> network name. Typically set via parameter_defaults in the resource registry. type: json # We define mappings to work around names that break when doing the # CamelCase to snake_case conversion to align with service_names ServiceNetMapDeprecatedMapping: default: MongoDbNetwork: MongodbNetwork RabbitMqNetwork: RabbitmqNetwork CephPublicNetwork: CephMonNetwork SwiftMgmtNetwork: SwiftStorageNetwork description: Mapping older deprecated service names, intended for internal use only, this will be removed in future. type: json parameter_groups: - label: deprecated description: Do not use deprecated params, they will be removed. parameters: - ServiceNetMapDeprecatedMapping outputs: service_net_map: value: map_merge: - {get_param: ServiceNetMapDefaults} - map_replace: - {get_param: ServiceNetMap} - keys: {get_param: ServiceNetMapDeprecatedMapping} service_net_map_lower: value: # This does a conversion from CamelCase to snake_case, # e.g HeatApiNetwork becomes heat_api_network so it # matches the service names. yaql: expression: dict($.data.map.items().select([ regex(`([a-z0-9])([A-Z])`).replace($[0], '\\1_\\2').toLower(), $[1]])) data: map: map_merge: - {get_param: ServiceNetMapDefaults} - map_replace: - {get_param: ServiceNetMap} - keys: {get_param: ServiceNetMapDeprecatedMapping}