Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert link on Ops Manager UI behaves unexpectedly for BOSH director tile #558

Open
yosepkim opened this issue Sep 2, 2021 · 0 comments
Projects

Comments

@yosepkim
Copy link

yosepkim commented Sep 2, 2021

After getting the tile settings using OM CLI (ex. om -e env.yml staged-config -p p-healthwatch -c >p-healthwatch.yml), pushing the same file to the OpsManager API (ex. om --env env/env.yml configure-product --config p-healthwatch.yml), this would show the Revert link only when applying changes to the BOSH director.

It is due to subnets' GUID not being persisted between API calls. Here are steps to reproduce:

om --env env.yml --trace staged-director-config --no-redact > director-config.yml
om --env env.yml --trace configure-director --config director-config.yml

Checking the API calls made you would notice that the guid subnets property is not set in the update API call.

GET /api/v0/staged/director/networks HTTP/1.1
Content-Type: application/json


HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Mon, 16 Aug 2021 08:22:45 GMT
Etag: W/"ef0611ed04a22b673223b1d91badd7ae"
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
Server: Ops Manager
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: cf3fdfcb-bdd4-4a3a-bdf7-0ebe3404097e
X-Runtime: 0.207417
X-Xss-Protection: 1; mode=block

2bf
{"icmp_checks_enabled":true,"networks":[{"guid":"25392115637e5bffae09","name":"infra","subnets":[{"guid":"0524239992263e835184","iaas_identifier":"Lab-env35","cidr":"10.213.49.128/25","dns":"10.192.2.10,10.192.2.11","gateway":"10.213.49.129","reserved_ip_ranges":"10.213.49.128-10.213.49.132,10.213.49.134,10.213.49.200-10.213.49.255","availability_zone_names":["az1","az2","az3"]}]},{"guid":"f35f8ba3f930be632d73","name":"service","subnets":[{"guid":"34161da42142a47b6803","iaas_identifier":"Lab-env35","cidr":"10.213.49.128/25","dns":"10.192.2.10,10.192.2.11","gateway":"10.213.49.129","reserved_ip_ranges":"10.213.49.128-10.213.49.217,10.213.49.255","availability_zone_names":["az1","az2","az3"]}]}]}
0


PUT /api/v0/staged/director/networks HTTP/1.1
Content-Type: application/json

{"icmp_checks_enabled":true,"networks":[{"guid":"25392115637e5bffae09","name":"infra","subnets":[{"availability_zone_names":["az1","az2","az3"],"cidr":"10.213.49.128/25","dns":"10.192.2.10,10.192.2.11","gateway":"10.213.49.129","iaas_identifier":"Lab-env35","reserved_ip_ranges":"10.213.49.128-10.213.49.132,10.213.49.134,10.213.49.200-10.213.49.255"}]},{"guid":"f35f8ba3f930be632d73","name":"service","subnets":[{"availability_zone_names":["az1","az2","az3"],"cidr":"10.213.49.128/25","dns":"10.192.2.10,10.192.2.11","gateway":"10.213.49.129","iaas_identifier":"Lab-env35","reserved_ip_ranges":"10.213.49.128-10.213.49.217,10.213.49.255"}]}]}
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Mon, 16 Aug 2021 08:22:48 GMT
Etag: W/"44136fa355b3678a1146ad16f7e8649e"
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Referrer-Policy: strict-origin-when-cross-origin
Server: Ops Manager
Strict-Transport-Security: max-age=31536000; includeSubDomains
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 48de9ff8-2ee6-4067-b597-db65980d9055
X-Runtime: 2.678686
X-Xss-Protection: 1; mode=block

2
{}
0

Checking the OM CLI source code: https://github.com/pivotal-cf/om/blob/main/api/director_service.go#L226-L263. It has a custom function to add the GUID for the network.

Last, I have checked the Ops Manager API would accept a payload with a GUID for subnets (https://github.com/pivotal-cf/om/blob/main/api/director_service.go#L226-L263)

director_service.go
func (a Api) addGUIDToExistingNetworks(networks Networks) (Networks, error) {
    existingNetworksResponse, err := a.sendAPIRequest("GET", "/api/v0/staged/director/networks", nil)
    if err != nil {
        return Networks{}, err
    }
    defer existingNetworksResponse.Body.Close()

    if existingNetworksResponse.StatusCode == http.StatusNotFound {
        a.logger.Println("unable to retrieve existing network configuration, attempting to configure anyway")
        return Networks{}, nil
    }

    if err = validateStatusOK(existingNetworksResponse); err != nil {
        return Networks{}, err
    }

    existingNetworksJSON, err := ioutil.ReadAll(existingNetworksResponse.Body)
    if err != nil {
        return Networks{}, fmt.Errorf("unable to read existing network configuration") // un-test: %w", erred
    }

    var existingNetworks Networks
    err = yaml.Unmarshal(existingNetworksJSON, &existingNetworks)
    if err != nil {
        return Networks{}, fmt.Errorf("problem retrieving existing networks: response is not well-formed: %w", err)
    }

    for _, network := range networks.Networks {
        for _, existingNetwork := range existingNetworks.Networks {
            if network.Name == existingNetwork.Name {
                network.GUID = existingNetwork.GUID
                break
            }
        }
    }

    return networks, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Releases
Next Release
Development

No branches or pull requests

1 participant