diff mbox series

[ovs-dev] ovs-ctl: Add new option to use short hostname.

Message ID 1538618123-88663-1-git-send-email-hzhou8@ebay.com
State Superseded
Headers show
Series [ovs-dev] ovs-ctl: Add new option to use short hostname. | expand

Commit Message

Han Zhou Oct. 4, 2018, 1:55 a.m. UTC
From: Han Zhou <hzhou8@ebay.com>

Current ovs-ctl forces to set full hostname in external-ids. In
some situation users may want to set short hostname. For example,
in OpenStack - OVN integration, Neutron uses the host-id provided
by Nova, which is usually short hostname, to set "requested-chassis"
in OVN. The mismatch in hypervisor's external-ids:hostname setting
causes OVN port binding failure. It can be overridden to short name
but a openvswitch restart using ovs-ctl would again set it to full
hostname. This patch ensures in such use cases --no-full-hostname
can be specified to ovs-ctl to set short hostname instead.

Signed-off-by: Han Zhou <hzhou8@ebay.com>
---
 utilities/ovs-ctl.in | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Aaron Conole Oct. 4, 2018, 7:23 p.m. UTC | #1
Han Zhou <zhouhan@gmail.com> writes:

> From: Han Zhou <hzhou8@ebay.com>
>
> Current ovs-ctl forces to set full hostname in external-ids. In
> some situation users may want to set short hostname. For example,
> in OpenStack - OVN integration, Neutron uses the host-id provided
> by Nova, which is usually short hostname, to set "requested-chassis"
> in OVN. The mismatch in hypervisor's external-ids:hostname setting
> causes OVN port binding failure. It can be overridden to short name
> but a openvswitch restart using ovs-ctl would again set it to full
> hostname. This patch ensures in such use cases --no-full-hostname
> can be specified to ovs-ctl to set short hostname instead.
>
> Signed-off-by: Han Zhou <hzhou8@ebay.com>
> ---
>  utilities/ovs-ctl.in | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> index 749de99..7651927 100644
> --- a/utilities/ovs-ctl.in
> +++ b/utilities/ovs-ctl.in
> @@ -38,6 +38,10 @@ insert_mod_if_required () {
>  set_hostname () {
>      # 'hostname -f' needs network connectivity to work.  So we should
>      # call this only after ovs-vswitchd is running.
> +    hn="$(hostname -f)"
> +    if test X$FULL_HOSTNAME = Xno; then
> +        hn="$(hostname)"
> +    fi

This will call hostname twice.  Might be better to write:

  if test X$FULL_HOSTNAME = Xno; then
      hn="$(hostname)"
  else
      hn="$(hostname -f)"
  fi

>      ovs_vsctl set Open_vSwitch . external-ids:hostname="$(hostname -f)"

I think this line also needs to be changed to use the new hn value like
so:

  ovs_vsctl set Open_vSwitch . external-ids:hostname="$hn"

>  }
>  
> @@ -289,6 +293,8 @@ enable_protocol () {
>  set_defaults () {
>      SYSTEM_ID=
>  
> +    FULL_HOSTNAME=yes
> +
>      DELETE_BRIDGES=no
>      DELETE_TRANSIENT_PORTS=no
>  
> @@ -374,6 +380,7 @@ Less important options for "start", "restart" and "force-reload-kmod":
>    --no-mlockall                  do not lock all of ovs-vswitchd into memory
>    --ovsdb-server-priority=NICE   set ovsdb-server's niceness (default: $OVSDB_SERVER_PRIORITY)
>    --ovs-vswitchd-priority=NICE   set ovs-vswitchd's niceness (default: $OVS_VSWITCHD_PRIORITY)
> +  --no-full-hostname             set short hostname instead of full hostname
>  
>  Debugging options for "start", "restart" and "force-reload-kmod":
>    --ovsdb-server-wrapper=WRAPPER
Han Zhou Oct. 4, 2018, 7:51 p.m. UTC | #2
On Thu, Oct 4, 2018 at 12:23 PM Aaron Conole <aconole@redhat.com> wrote:
>
> Han Zhou <zhouhan@gmail.com> writes:
>
> > From: Han Zhou <hzhou8@ebay.com>
> >
> > Current ovs-ctl forces to set full hostname in external-ids. In
> > some situation users may want to set short hostname. For example,
> > in OpenStack - OVN integration, Neutron uses the host-id provided
> > by Nova, which is usually short hostname, to set "requested-chassis"
> > in OVN. The mismatch in hypervisor's external-ids:hostname setting
> > causes OVN port binding failure. It can be overridden to short name
> > but a openvswitch restart using ovs-ctl would again set it to full
> > hostname. This patch ensures in such use cases --no-full-hostname
> > can be specified to ovs-ctl to set short hostname instead.
> >
> > Signed-off-by: Han Zhou <hzhou8@ebay.com>
> > ---
> >  utilities/ovs-ctl.in | 7 +++++++
> >  1 file changed, 7 insertions(+)
> >
> > diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
> > index 749de99..7651927 100644
> > --- a/utilities/ovs-ctl.in
> > +++ b/utilities/ovs-ctl.in
> > @@ -38,6 +38,10 @@ insert_mod_if_required () {
> >  set_hostname () {
> >      # 'hostname -f' needs network connectivity to work.  So we should
> >      # call this only after ovs-vswitchd is running.
> > +    hn="$(hostname -f)"
> > +    if test X$FULL_HOSTNAME = Xno; then
> > +        hn="$(hostname)"
> > +    fi
>
> This will call hostname twice.  Might be better to write:
>
>   if test X$FULL_HOSTNAME = Xno; then
>       hn="$(hostname)"
>   else
>       hn="$(hostname -f)"
>   fi
>
> >      ovs_vsctl set Open_vSwitch . external-ids:hostname="$(hostname -f)"
>
> I think this line also needs to be changed to use the new hn value like
> so:
>
>   ovs_vsctl set Open_vSwitch . external-ids:hostname="$hn"
>
oops. somehow I made a stupid mistake when porting the patch from my test
machine to the actual commit. Thanks for figuring out and I am sending v2.
diff mbox series

Patch

diff --git a/utilities/ovs-ctl.in b/utilities/ovs-ctl.in
index 749de99..7651927 100644
--- a/utilities/ovs-ctl.in
+++ b/utilities/ovs-ctl.in
@@ -38,6 +38,10 @@  insert_mod_if_required () {
 set_hostname () {
     # 'hostname -f' needs network connectivity to work.  So we should
     # call this only after ovs-vswitchd is running.
+    hn="$(hostname -f)"
+    if test X$FULL_HOSTNAME = Xno; then
+        hn="$(hostname)"
+    fi
     ovs_vsctl set Open_vSwitch . external-ids:hostname="$(hostname -f)"
 }
 
@@ -289,6 +293,8 @@  enable_protocol () {
 set_defaults () {
     SYSTEM_ID=
 
+    FULL_HOSTNAME=yes
+
     DELETE_BRIDGES=no
     DELETE_TRANSIENT_PORTS=no
 
@@ -374,6 +380,7 @@  Less important options for "start", "restart" and "force-reload-kmod":
   --no-mlockall                  do not lock all of ovs-vswitchd into memory
   --ovsdb-server-priority=NICE   set ovsdb-server's niceness (default: $OVSDB_SERVER_PRIORITY)
   --ovs-vswitchd-priority=NICE   set ovs-vswitchd's niceness (default: $OVS_VSWITCHD_PRIORITY)
+  --no-full-hostname             set short hostname instead of full hostname
 
 Debugging options for "start", "restart" and "force-reload-kmod":
   --ovsdb-server-wrapper=WRAPPER