示例#1
0
func (s SubnetChecker) CheckSubnets(manifestFilename string) (bool, error) {
	networks, err := manifests.ReadNetworksFromManifest(manifestFilename)
	if err != nil {
		return false, err
	}

	manifestSubnetMap := mapSubnets(subnetsFromManifestNetworks(networks))

	session, err := s.awsClient.Session()
	if err != nil {
		return false, err
	}

	awsSubnets, err := s.awsClient.FetchSubnets(session, subnetIdsFromSubnets(manifestSubnetMap))
	if err != nil {
		return false, err
	}
	awsSubnetMap := mapSubnets(awsSubnets)

	for id, manifestSubnet := range manifestSubnetMap {
		awsSubnet, ok := awsSubnetMap[id]
		if !ok {
			return false, nil
		}
		if awsSubnet.CIDRBlock != manifestSubnet.CIDRBlock {
			return false, nil
		}
	}

	return true, nil
}
示例#2
0
				_, err = manifests.ReadManifest(manifestFile)
				Expect(err.Error()).To(ContainSubstring("mapping values are not allowed in this context"))
			})

			It("returns an error when the file doesn't exist", func() {
				_, err = manifests.ReadManifest("/nonexistent/file")
				Expect(err.Error()).To(ContainSubstring("no such file or directory"))
			})
		})
	})

	Describe("ReadNetworksFromManifest", func() {
		It("reads the network information from the given manifest", func() {
			writeManifestWithBody(manifestsDirectory, "manifest-with-subnets.yml", manifestWithSubnets)

			networks, err := manifests.ReadNetworksFromManifest(filepath.Join(manifestsDirectory, "manifest-with-subnets.yml"))
			Expect(err).NotTo(HaveOccurred())

			Expect(networks[0].Subnets[0].CloudProperties.Subnet).To(Equal("subnet-1"))
			Expect(networks[0].Subnets[0].Range).To(Equal("10.0.20.0/24"))

			Expect(networks[1].Subnets[0].CloudProperties.Subnet).To(Equal("subnet-2"))
			Expect(networks[1].Subnets[0].Range).To(Equal("10.1.20.0/24"))
		})

		Context("failure cases", func() {
			It("returns an error when given invalid yaml", func() {
				manifestFile := filepath.Join(manifestsDirectory, "invalid_manifest.yml")
				err := ioutil.WriteFile(manifestFile, []byte("not: valid: yaml:"), os.ModePerm)
				Expect(err).NotTo(HaveOccurred())