-
Notifications
You must be signed in to change notification settings - Fork 42
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
CP-26352 Port xcp-networkd from Camlp4 to PPX #128
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like that we are removing all the named parameters here. is there any way to re-enable these?
lib/network_config.ml
Outdated
config_json |> Jsonrpc.of_string |> config_t_of_rpc | ||
match config_json |> Jsonrpc.of_string |> Rpcmarshal.unmarshal typ_of_config_t with | ||
| Result.Ok v -> v | ||
| Result.Error e -> raise Read_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a debug statement that records the error in e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do when I add code to fix the read error.
networkd/network_monitor.ml
Outdated
let payload = stats |> rpc_of_stats_t |> Jsonrpc.to_string in | ||
let checksum = payload |> Digest.string |> Digest.to_hex in | ||
let payload = stats |> Rpcmarshal.marshal typ_of_stats_t |> Jsonrpc.to_string in | ||
let checksum = payload |> Digest.string |> Digest.to_hex in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use tabs here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
networkd/network_monitor_thread.ml
Outdated
@@ -229,7 +229,7 @@ let rec monitor dbg () = | |||
) devs | |||
in | |||
|
|||
let bonds : (string * string list) list = Network_server.Bridge.get_all_bonds () dbg ~from_cache:true () in | |||
let bonds : (string * string list) list = Network_server.Bridge.get_all_bonds dbg true in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please keep the label if it does not confuse the compiler. That true
on its own is confusing, I'd rather do
let from_cache = true in ...
if we cannot keep the labels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly we cannot keep the labels, so we should add the let
statement
networkd/network_server.ml
Outdated
@@ -68,13 +68,13 @@ let on_timer () = | |||
|
|||
let reopen_logs _ () = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove _
here as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather remove the function as it is out of use.
debug "Configuring IPv4 static routes for %s: %s" name (String.concat ", " (List.map (fun (i, p, g) -> | ||
Printf.sprintf "%s/%d/%s" (Unix.string_of_inet_addr i) p (Unix.string_of_inet_addr g)) routes)); | ||
debug "Configuring IPv4 static routes for %s: %s" name (String.concat ", " (List.map (fun r -> | ||
Printf.sprintf "%s/%d/%s" (Unix.string_of_inet_addr r.subnet) r.netmask (Unix.string_of_inet_addr r.gateway)) routes)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks much better now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I have a few suggestions for improvements to the code you haven't actually touched, mostly stylistic:
-
As
List.remove_assoc
is idempotent, you could probably remove the redundantList.mem_assoc
here, though I'm not sure if you could also do it for the use here. -
Functions like
vlan_bug_workaround
useif List.mem_assoc [...] then List.assoc [...]
where you could just usetry List.assoc [...] with Not_found -> None
-
We're throwing around a lot of mentions of "UP" and "DOWN", would it be better to globally declare
let up_str = "UP"
andlet down_str = "DOWN"
? That way, if the string is changed in future, we won't have to update all these functions, just the values themselves. -
A thought: lines 969-971 of
make_config
look like they could be refactored with use of the built-incompare
for options. This depends on whether the type ofconfig
is likely to change, so up to you/other people with knowledge on this.
Anyway, these are all optional changes, so it's up to you.
Debug.with_thread_associated dbg (fun () -> | ||
match Linux_bonding.get_bond_master_of name with | ||
| Some master -> Proc.get_bond_slave_mac master name | ||
| None -> Ip.get_mac name | ||
) () | ||
|
||
let is_up _ dbg ~name = | ||
let is_up dbg name = | ||
Debug.with_thread_associated dbg (fun () -> | ||
if List.mem name (Sysfs.list ()) then | ||
Ip.is_up name | ||
else | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour is already encoded in Ip.is_up
as below, so it might be more efficient to remove lines 149, 151-152?
let is_up dev = try (List.mem "UP" (get_link_flags dev) with _ -> false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, if change it as you did, will remove the check of the dev
existence in sysfs.
Could you name this PR to something like "CP-26352: Port xcp-networkd from Camlp4 to PPX", so it's relevant to the repo you've modified? That way we can tell all your PRs apart by title. |
lib/network_config.ml
Outdated
@@ -114,7 +116,9 @@ let write_config config = | |||
let read_config () = | |||
try | |||
let config_json = Xapi_stdext_unix.Unixext.string_of_file config_file_path in | |||
config_json |> Jsonrpc.of_string |> config_t_of_rpc | |||
match config_json |> Jsonrpc.of_string |> Rpcmarshal.unmarshal typ_of_config_t with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the part that we need to test very well: it needs to be able to read a JSON file with config that was written by the old version (pre-PPX) of the software, because that is what happens on upgrade.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An issue here should make the update/upgrade tests in bvt and bst fail right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most likely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think it should be OK except the interface_config_t.ipv4_routes
because it changes from tuple list
to a struct list
.
I will test and add code to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have tested this case by following:
- install XS of ring3 master branch
- Configure
static_routes
for network by:
xe network-param-set uuid=a09c23c3-9a46-e1aa-c7c8-6efb5b3256de other-config:static-routes="192.168.2.0/24/192.168.2.1"
- plug the PIF in the network
- send
kill
signal to networkc process so it will persist the configuration tonetworkd.db
- replace
xapi
andxcp-networkd
by that of my private branch - restart toolstack
- check xensource.log
Expect result: We should get Result.Error
when unmarshalling
Actual result: Got Result.Ok
The test point is the type change of interface_config_t .ipv4_routes
from
(Unix.inet_addr * int * Unix.inet_addr) list
to
type ipv4_route_t = {
subnet : Unix.inet_addr;
netmask : int;
gateway : Unix.inet_addr;
} [@@deriving rpcty]
It is expected to get some error at runtime but actually not.
Thd network.db file content is:
{"interface_config":{"xenbr0":{"ipv4_conf":"DHCP4","ipv6_conf":"Linklocal6","ipv4_routes":[["192.168.2.0",24,"192.168.2.1"]],"dns":[[],[]],"mtu":1500,"ethtool_settings":{},"ethtool_offload":{"gro":"on","lro":"off"},"persistent_i":true},"eth0":{"ipv4_conf":"None4","ipv6_conf":"None6","ipv4_routes":[],"dns":[[],[]],"mtu":1500,"ethtool_settings":{},"ethtool_offload":{"gro":"on","lro":"off"},"persistent_i":true},"eth1":{"ipv4_conf":"None4","ipv6_conf":"None6","ipv4_routes":[],"dns":[[],[]],"mtu":1500,"ethtool_settings":{},"ethtool_offload":{"gro":"on","lro":"off"},"persistent_i":true},"xenbr1":{"ipv4_conf":"None4","ipv6_conf":"Linklocal6","ipv4_routes":[],"dns":[[],[]],"mtu":1500,"ethtool_settings":{},"ethtool_offload":{"gro":"on","lro":"off"},"persistent_i":true}},"bridge_config":{"xenbr0":{"ports":{"eth0":{"interfaces":["eth0"],"bond_properties":{},"kind":"Basic"}},"bridge_mac":"c8:1f:66:ba:ff:2b","igmp_snooping":false,"other_config":{"static-routes":"192.168.2.0/24/192.168.2.1","memory-ratio-hvm":"0.25","memory-ratio-pv":"0.25","network-uuids":"a09c23c3-9a46-e1aa-c7c8-6efb5b3256de"},"persistent_b":true},"xenbr1":{"ports":{"eth1":{"interfaces":["eth1"],"bond_properties":{},"kind":"Basic"}},"bridge_mac":"c8:1f:66:ba:ff:2c","igmp_snooping":false,"other_config":{"memory-ratio-hvm":"0.25","memory-ratio-pv":"0.25","network-uuids":"92958b17-e115-0a17-acf8-12b2bbeea0c8"},"persistent_b":true}},"gateway_interface":"xenbr0","dns_interface":"xenbr0"}
Update 1.
OK, now I find the root cause is we defined a default value for interface_config_t .ipv4_routes
so if unmarshal error, it will get the default value []
.
The code generated by rewriter is
(fun interface_config_t_dns ->
(match getter.Rpc.Types.fget
"ipv4_routes"
(let open! Rpc.Types in
List
(let open! Rpc.Types in
typ_of_ipv4_route_t))
with
| Result.Ok _ as y -> y
| Result.Error _ -> Result.Ok [])
I have 2 proposed solutions:
- Can we add some rewriter or hook code to https://github.com/krizex/xcp-idl/blob/private/yangqi/CP-26352/network/network_interface.ml#L107 to handle this case?
- Convert the configuration file to new format (for
ipv4_routes
field) before unmarshalling it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have updated this PR by implemented option 2.
090b340
@mseri Yes, two options:
|
@minishrink Thanks, I will update the title and commit message. Wrt to the optional comments you mentioned, I'd like to keep the code as is because that's not in the scope of this pull request. I'd like to keep this PR as small as possible. We could apply the minor changes in the future. |
1. update implementation per interface changes 1. for interface implementation, move labeled parameter and optional parameter to positional parameter and remove useless tail unit parameter Signed-off-by: Yang Qian <yang.qian@citrix.com>
9ffeba6
to
018c20d
Compare
Update with some minor changes. |
Signed-off-by: Yang Qian <yang.qian@citrix.com>
Ring3 BVT passed in job 79965 |
I am going to do a manual merge to master and close the PR to ppx_network |
to positional parameter and remove useless tail unit parameter
Signed-off-by: Yang Qian yang.qian@citrix.com
This PR should goes in with xapi-project/xcp-idl#189
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)