Skip to content

Commit

Permalink
ir: Check UN/LOCODE attributes, not attach them
Browse files Browse the repository at this point in the history
Closes #2612.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
  • Loading branch information
carpawell committed Nov 16, 2023
1 parent eb065fc commit 43ddb58
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Changelog for NeoFS Node
- New optimized SDK version is integrated (#2622)
- IR uses internal LOCODE DB from Go package (#2610)
- Contract group for the committee is no longer registered/used in the Sidechain auto-deployment (#2642)
- IR does not change SNs' attributes, SNs expand UN/LOCODE attributes do it themselves (#2612)

### Removed
- deprecated `no-precheck` flag of `neofs-cli container set-eacl` (#2496)
Expand Down
38 changes: 30 additions & 8 deletions pkg/innerring/processors/netmap/nodevalidation/locode/calls.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,38 @@ func (v *Validator) VerifyAndUpdate(n *netmap.NodeInfo) error {
return fmt.Errorf("could not get locode record from DB: %w", err)
}

n.SetCountryCode(key.CountryCode().String())
n.SetCountryName(record.Country)
n.SetLocationName(record.Location)
n.SetContinentName(record.Cont.String())
if subDivCode := record.SubDivCode; subDivCode != "" {
n.SetSubdivisionCode(subDivCode)
err = checkAttribute(n, "CountryCode", key.CountryCode().String())
if err != nil {
return err
}
err = checkAttribute(n, "Country", record.Country)
if err != nil {
return err
}
err = checkAttribute(n, "Location", record.Location)
if err != nil {
return err
}
err = checkAttribute(n, "Continent", record.Cont.String())
if err != nil {
return err
}
err = checkAttribute(n, "SubDivCode", record.SubDivCode)
if err != nil {
return err
}
err = checkAttribute(n, "SubDiv", record.SubDivName)
if err != nil {
return err
}

return nil
}

if subDivName := record.SubDivName; subDivName != "" {
n.SetSubdivisionName(subDivName)
func checkAttribute(n *netmap.NodeInfo, key, expectedVal string) error {
val := n.Attribute(key)
if val != expectedVal {
return fmt.Errorf("unexpected '%s' attribute value: want '%s', got '%s'", key, expectedVal, val)
}

return nil
Expand Down
72 changes: 62 additions & 10 deletions pkg/innerring/processors/netmap/nodevalidation/locode/calls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,70 @@ func TestValidator_VerifyAndUpdate(t *testing.T) { // test record with valid but
require.Error(t, err)
})

n := nodeInfoWithSomeAttrs()
t.Run("correct code", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{k.CountryCode().String(), k.LocationCode().String()})

addLocodeAttr(n, [2]string{k.CountryCode().String(), k.LocationCode().String()})
n.SetAttribute("CountryCode", k.CountryCode().String())
n.SetAttribute("Country", r.Country)
n.SetAttribute("Location", r.Location)
n.SetAttribute("SubDivCode", r.SubDivCode)
n.SetAttribute("SubDiv", r.SubDivName)
n.SetAttribute("Continent", r.Cont.String())

err := validator.VerifyAndUpdate(n)
require.NoError(t, err)
require.NoError(t, validator.VerifyAndUpdate(n))
})

t.Run("invalid SN expansion", func(t *testing.T) {

t.Run("invalid Country", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{"RU", "SPB"})
n.SetAttribute("CountryCode", r.Country+"bad")

require.Error(t, validator.VerifyAndUpdate(n))
})

t.Run("invalid Location", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{"RU", "SPB"})
n.SetAttribute("Location", r.Location+"bad")

require.Error(t, validator.VerifyAndUpdate(n))
})

require.Equal(t, k.CountryCode().String(), n.Attribute("CountryCode"))
require.Equal(t, r.Country, n.Attribute("Country"))
require.Equal(t, r.Location, n.Attribute("Location"))
require.Equal(t, r.SubDivCode, n.Attribute("SubDivCode"))
require.Equal(t, r.SubDivName, n.Attribute("SubDiv"))
require.Equal(t, r.Cont.String(), n.Attribute("Continent"))
t.Run("invalid SubDivCode", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{"RU", "SPB"})
n.SetAttribute("SubDivCode", r.SubDivCode+"bad")

require.Error(t, validator.VerifyAndUpdate(n))
})

t.Run("invalid SubDivName", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{"RU", "SPB"})
n.SetAttribute("SubDivName", r.SubDivName+"bad")

require.Error(t, validator.VerifyAndUpdate(n))
})

t.Run("invalid Continent", func(t *testing.T) {
n := nodeInfoWithSomeAttrs()
addLocodeAttr(n, [2]string{"RU", "SPB"})
n.SetAttribute("Continent", r.Cont.String()+"bad")

require.Error(t, validator.VerifyAndUpdate(n))
})
})
})
}

func copyRecord(r locodedb.Record) locodedb.Record {
rCopy := r
rCopy.Point = locodedb.NewPoint(r.Point.Latitude(), r.Point.Longitude())
contCopy := *rCopy.Cont
rCopy.Cont = &contCopy

return rCopy
}

0 comments on commit 43ddb58

Please sign in to comment.