F5Networks / f5-cloud-libs

Node.js libraries to assist in cloud deployments.
Apache License 2.0
29 stars 14 forks source link

updateAutoScaleUcs replaces incorrect values #28

Closed chen23 closed 1 year ago

chen23 commented 4 years ago

When loading a Ucs file the updateAutoScaleUCs file will replace values that it should not.

The following is an example where it is also updating ltm nodes (it should not).

/config/cloud/azure/node_modules/\@f5devcentral/f5-cloud-libs/scripts/updateAutoScaleUcs  --cloud-provider azure --original-ucs ~/old.ucs --updated-ucs ~/foobar.ucs

and compare bigip.conf

[admin@erchen-autoscale-waf-vmss_3:Active:Standalone] ~ # diff -C 1 new/config/bigip.conf tmp/config/bigip.conf
*** new/config/bigip.conf   2020-10-22 02:12:57.000000000 +0000
--- tmp/config/bigip.conf   2020-10-22 01:02:25.000000000 +0000
***************
*** 55,61 ****
  }
! ltm node /Common/10.1.1.10 {
!     address 10.1.1.10
  }
! ltm node /Common/10.1.1.100 {
!     address 10.1.1.100
  }
--- 55,61 ----
  }
! ltm node /Common/10.1.10.10 {
!     address 10.1.10.10
  }
! ltm node /Common/10.1.10.100 {
!     address 10.1.10.100
  }
***************
*** 63,69 ****
      members {
!         /Common/10.1.1.10:80 {
!             address 10.1.1.10
          }
!         /Common/10.1.1.100:80 {
!             address 10.1.1.100
          }
--- 63,69 ----
      members {
!         /Common/10.1.10.10:80 {
!             address 10.1.10.10
          }
!         /Common/10.1.10.100:80 {
!             address 10.1.10.100
          }
***************
*** 97,99 ****
  net route /Common/default {
!     gw 10.1.1.1
      network default
--- 97,99 ----
  net route /Common/default {
!     gw 10.1.10.1
      network default
***************
*** 101,103 ****
  net route /Common/dhclient_route1 {
!     gw 10.1.1.1
      network 168.63.129.16/32
--- 101,103 ----
  net route /Common/dhclient_route1 {
!     gw 10.1.10.1
      network 168.63.129.16/32
chen23 commented 4 years ago

The following appears to address the issue above.

diff --git a/scripts/updateAutoScaleUcs b/scripts/updateAutoScaleUcs
index c8b73bf..9c5f4da 100755
--- a/scripts/updateAutoScaleUcs
+++ b/scripts/updateAutoScaleUcs
@@ -119,7 +119,8 @@ def replace(source_file_path, pattern, substring):
     with open(target_file_path, 'w') as target_file:
         with open(source_file_path, 'r') as source_file:
             for line in source_file:
-                target_file.write(line.replace(pattern, substring))
+                newline = re.sub("(%s)$" %(pattern),substring,line)
+                newline = re.sub("(%s)\/" %(pattern),substring+'/',newline)
+                target_file.write(newline)
     os.remove(source_file_path)
     shutil.move(target_file_path, source_file_path)

output

*** new/config/bigip.conf   2020-10-22 02:20:25.000000000 +0000
--- tmp/config/bigip.conf   2020-10-22 01:02:25.000000000 +0000
***************
*** 97,99 ****
  net route /Common/default {
!     gw 10.1.1.1
      network default
--- 97,99 ----
  net route /Common/default {
!     gw 10.1.10.1
      network default
***************
*** 101,103 ****
  net route /Common/dhclient_route1 {
!     gw 10.1.1.1
      network 168.63.129.16/32
--- 101,103 ----
  net route /Common/dhclient_route1 {
!     gw 10.1.10.1
      network 168.63.129.16/32
shyawnkarim commented 1 year ago

Closing. This issue was resolved with a previous release.