Skip to content

Commit

Permalink
Merge "[Fabric] Fabric Python3 Stage3 changes"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul v3 CI authored and opencontrail-ci-admin committed Feb 10, 2020
2 parents 805ce44 + ea54dc3 commit eadcbbc
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
8 changes: 5 additions & 3 deletions src/config/api-server/vnc_cfg_api_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,12 +402,14 @@ def encrypt_password(pwd_key, dict_password):
if key_padding_len == 0:
key_padding_len = 1
key = pwd_key.rjust(16 * key_padding_len)
cipher = AES.new(key, AES.MODE_ECB)
key_b = key.encode()
cipher = AES.new(key_b, AES.MODE_ECB)

text_padding_len = (len(dict_password) + 16 - 1) // 16
if text_padding_len == 0:
text_padding_len = 1
padded_text = dict_password.rjust(16 * text_padding_len)
password = base64.b64encode(cipher.encrypt(padded_text))
padded_text_b = padded_text.encode()
password = base64.b64encode(cipher.encrypt(padded_text_b))
return password
# end encrypt_password
# end encrypt_password
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def _calculate_devices_with_critical_routing_bridging_roles(self):
FilterModule.critical_routing_bridging_roles:
self.critical_routing_bridging_roles_count[
critical_routing_bridging_role] = 0
for device_uuid, device_info in self.device_table.iteritems():
for device_uuid, device_info in list(self.device_table.items()):
for routing_bridging_role in device_info.get('rb_roles'):
if routing_bridging_role in\
FilterModule.critical_routing_bridging_roles:
Expand All @@ -346,13 +346,13 @@ def _calculate_devices_with_critical_routing_bridging_roles(self):
def _calc_max_number_of_repr_of_critical_rb_roles_per_batch(self):
self.max_number_of_repr_of_critical_rb_roles_per_batch = {}
for role_name, number_of_occurences \
in self.critical_routing_bridging_roles_count.iteritems():
in list(self.critical_routing_bridging_roles_count.items()):
self.max_number_of_repr_of_critical_rb_roles_per_batch[role_name] \
= number_of_occurences / 2 + number_of_occurences % 2

def _calculate_max_number_of_spines_updated_in_batch(self):
number_of_spines = 0
for device_uuid, device_info in self.device_table.iteritems():
for device_uuid, device_info in list(self.device_table.items()):
if device_info.get('physical_role') == 'spine':
number_of_spines += 1
self.max_number_of_spines_updated_in_batch = \
Expand Down
12 changes: 6 additions & 6 deletions src/config/fabric-ansible/job_manager/job_log_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from builtins import map
from builtins import object
from builtins import range
import ConfigParser as configparser
from six.moves.configparser import SafeConfigParser
from decimal import Decimal, getcontext
import json
import random
Expand All @@ -24,10 +24,10 @@
from pysandesh.gen_py.sandesh.ttypes import SandeshLevel
from pysandesh.sandesh_base import Sandesh
from pysandesh.sandesh_base import SandeshConfig
from sandesh.job.ttypes import JobLog
from sandesh.job.ttypes import JobLogEntry
from sandesh.job.ttypes import PRouterOnboardingLog
from sandesh.job.ttypes import PRouterOnboardingLogEntry
from .sandesh.job.ttypes import JobLog
from .sandesh.job.ttypes import JobLogEntry
from .sandesh.job.ttypes import PRouterOnboardingLog
from .sandesh.job.ttypes import PRouterOnboardingLogEntry


from job_manager.job_exception import JobException
Expand Down Expand Up @@ -115,7 +115,7 @@ def parse_logger_args(self, config_args):
sandeshopts = SandeshConfig.get_default_options()

if config_args.get("fabric_ansible_conf_file"):
config = configparser.SafeConfigParser()
config = SafeConfigParser()
config.read(config_args['fabric_ansible_conf_file'])
if 'DEFAULTS' in config.sections():
defaults.update(dict(config.items("DEFAULTS")))
Expand Down
6 changes: 4 additions & 2 deletions src/config/fabric-ansible/job_manager/job_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ def decrypt_password(encrypted_password=None, pwd_key=None):
raise ValueError("No password to decrypt")

key = pwd_key[-32:].rjust(16)
cipher = AES.new(key, AES.MODE_ECB)
key_b = key.encode()
cipher = AES.new(key_b, AES.MODE_ECB)

password = cipher.decrypt(base64.b64decode(encrypted_password))
encrypted_password_b = encrypted_password.encode()
password = cipher.decrypt(base64.b64decode(encrypted_password_b))
return password.strip()


Expand Down
6 changes: 3 additions & 3 deletions src/config/fabric-ansible/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
contrail-config-common
contrail-api-client
sandesh
sandesh-common
gevent==1.1.2
gevent==1.3
kombu==4.0.2
timeout-decorator
subprocess32
jsonschema
inflection>=0.3.1
pycrypto
pycryptodome
vine==1.1.3
pyroute2
sandesh==0.1dev
6 changes: 0 additions & 6 deletions src/config/fabric-ansible/test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@ pyaml
python-keystoneclient
python-novaclient
webtest
sandesh
sandesh_common
contrail-api-client
contrail-api-server
timeout-decorator
subprocess32
pycrypto
python-swiftclient
ansible

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/config/fabric-ansible/test/test_job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_execute_job_success(self):
# create job template
play_info = PlaybookInfoType(playbook_uri='job_manager_test.yml',
vendor='Juniper',
device_family='MX')
device_family='MX', sequence_no=0)
playbooks_list = PlaybookInfoListType(playbook_info=[play_info])
job_template = JobTemplate(job_template_type='workflow',
job_template_multi_device_job=False,
Expand All @@ -78,11 +78,11 @@ def test_execute_job_success_multiple_templates(self):
# create job template
play_info = PlaybookInfoType(playbook_uri='job_manager_test.yml',
vendor='Juniper',
device_family='MX')
device_family='MX', sequence_no=0)
play_info1 = PlaybookInfoType(
playbook_uri='job_manager_test_multiple.yml',
vendor='Juniper',
device_family='QFX')
device_family='QFX', sequence_no=1)
playbooks_list = PlaybookInfoListType(playbook_info=[play_info,
play_info1])
job_template = JobTemplate(job_template_type='workflow',
Expand All @@ -108,10 +108,10 @@ def test_execute_job_success_multiple_templates(self):
# to test the case when only device vendor is passed in job_template_input
def test_execute_job_with_vendor_only(self):
play_info = PlaybookInfoType(playbook_uri='job_manager_test.yaml',
vendor='Juniper')
vendor='Juniper', sequence_no=0)
play_info1 = PlaybookInfoType(
playbook_uri='job_manager_test_multiple.yml',
vendor='Juniper')
vendor='Juniper', sequence_no=1)

playbooks_list = PlaybookInfoListType(
playbook_info=[play_info, play_info1])
Expand All @@ -138,10 +138,10 @@ def test_execute_job_with_vendor_only(self):
def test_execute_job_multiple_device_families(self):
play_info_mx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='MX')
vendor='Juniper', device_family='MX', sequence_no=0)
play_info_qfx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='QFX')
vendor='Juniper', device_family='QFX', sequence_no=1)

playbooks_list = PlaybookInfoListType(
playbook_info=[play_info_qfx, play_info_mx])
Expand Down Expand Up @@ -173,13 +173,13 @@ def test_execute_job_multiple_device_families(self):
def test_execute_job_multiple_device_families_multiple_playbooks(self):
play_info_mx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='MX')
vendor='Juniper', device_family='MX', sequence_no=0)
play_info_qfx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='QFX')
vendor='Juniper', device_family='QFX', sequence_no=1)
play_info_2 = PlaybookInfoType(
playbook_uri='job_manager_test2.yaml',
vendor='Juniper')
vendor='Juniper', sequence_no=2)

playbooks_list = PlaybookInfoListType(
playbook_info=[play_info_qfx, play_info_mx, play_info_2])
Expand Down Expand Up @@ -210,13 +210,13 @@ def test_execute_job_multiple_device_families_multiple_playbooks(self):
def test_execute_job_multiple_vendors_multiple_playbooks(self):
play_info_juniper_mx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='MX')
vendor='Juniper', device_family='MX', sequence_no=0)
play_info_juniper_qfx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='QFX')
vendor='Juniper', device_family='QFX', sequence_no=1)
play_info_arista_df = PlaybookInfoType(
playbook_uri='job_manager_test2.yaml',
vendor='Arista', device_family='df')
vendor='Arista', device_family='df', sequence_no=2)
playbooks_list = PlaybookInfoListType(
playbook_info=[play_info_arista_df,
play_info_juniper_qfx,
Expand Down Expand Up @@ -246,9 +246,9 @@ def test_execute_job_multiple_vendors_multiple_playbooks(self):
def test_execute_job_no_vendor(self):
play_info_juniper_qfx = PlaybookInfoType(
playbook_uri='job_manager_test.yaml',
vendor='Juniper', device_family='QFX')
vendor='Juniper', device_family='QFX', sequence_no=0)
play_info_vendor_agnostic = PlaybookInfoType(
playbook_uri='job_manager_test2.yaml')
playbook_uri='job_manager_test2.yaml', sequence_no=1)
playbooks_list = PlaybookInfoListType(
playbook_info=[play_info_juniper_qfx,
play_info_vendor_agnostic])
Expand Down
2 changes: 1 addition & 1 deletion src/config/fabric-ansible/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[tox]
minversion = 1.6
# Test envs list buid and run by default
envlist = py27
envlist = py27,py36

# Common env configuration
[testenv]
Expand Down

0 comments on commit eadcbbc

Please sign in to comment.